Jump to content

[SOLVED] Pinging port returns false


smc

Recommended Posts

Hello,

 

This is actually a branch on someone else's question but I figured it deserved its own topic. I have a code that pings a server and returns whether it is open on that port or not. Here is the code:

 

<?php
$ip = "00.000.00.00";
$port = "80";

$sock = @fsockopen(  $ip, $port, $num, $error, 10 );

if( !$sock ){

echo( "It appears to be closed" );

}

if( $sock ){

echo( "It appears to be open" );
fclose($sock);

}
?>

 

The problem is on more specific ports (ports that require opening and aren't genericly opened) return as false. However when I use http://www.t1shopper.com/tools/port-scanner/ it registers as open.

 

Do you see anything that might be causing this to return false?

Link to comment
Share on other sites

Theres really nothing to be specific about other than it is a non-standard port, in this case 9339, however the same case is true with other ports on other machines.

 

There must be something wrong with the code so that it isn't properly detecting the port, or is there additional functions I can add to the script such as packet monitoring that would fix it?

Link to comment
Share on other sites

You can test it by running the code you posted.. if it doesn't work, you're firewalled  :P

 

If you are running the script from a web hosting service, then I would guess that's your problem.  If it works for port 80 but not for any non-standard port, then I would be 99% sure that's your problem.

 

If you're running the script from home, then it would depend on your ISP .. usually ISPs don't block such traffic, otherwise they would interfere with online gaming.  But webhosts are different.

Link to comment
Share on other sites

Hmm.. a proxy is possible.  You need one that can be connected to on port 80, but can send data out to any other port number.  An SSL proxy might be able to do that (using the CONNECT method).  I'm not sure about HTTP proxies, because I assume port 9339 is not a webserver.  You may be able to distinguish connection and non-connection from how the proxy acts though..

 

I wouldn't go for packet based methods because

 

1.  They are complex.

2.  They require superuser access, which you may not have.

3.  The probably won't work, unless the firewall is badly configured.

Link to comment
Share on other sites

Alright well since I'd rather not go 3rd party I've just settled for a server ping as opposed to a port ping.

 

Now my question is something broader. Is there a handy function that gets the geo-political location of the IP hostname?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.