smc Posted June 12, 2007 Share Posted June 12, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/ Share on other sites More sharing options...
trq Posted June 12, 2007 Share Posted June 12, 2007 $port should be an integer, not a string. $port = 80; Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272784 Share on other sites More sharing options...
smc Posted June 12, 2007 Author Share Posted June 12, 2007 Still no dice. Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272789 Share on other sites More sharing options...
btherl Posted June 12, 2007 Share Posted June 12, 2007 Can you be more specific about which ports, and which services you are testing for? Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272793 Share on other sites More sharing options...
smc Posted June 12, 2007 Author Share Posted June 12, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272797 Share on other sites More sharing options...
btherl Posted June 12, 2007 Share Posted June 12, 2007 I tested your code here and it works fine on non-standard ports (22 and 5433 I tested). Are you running it from a web host which may firewall outgoing traffic to non-standard ports? Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272802 Share on other sites More sharing options...
smc Posted June 12, 2007 Author Share Posted June 12, 2007 I'm not sure to be honest, how can I test for it? Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272805 Share on other sites More sharing options...
trq Posted June 12, 2007 Share Posted June 12, 2007 I'm not sure to be honest, how can I test for it? I think you just have. Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272807 Share on other sites More sharing options...
btherl Posted June 12, 2007 Share Posted June 12, 2007 You can test it by running the code you posted.. if it doesn't work, you're firewalled 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. Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272808 Share on other sites More sharing options...
smc Posted June 12, 2007 Author Share Posted June 12, 2007 Hm. Do you know of anyway I can do it to get around the problem? Packets perhaps? Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272809 Share on other sites More sharing options...
trq Posted June 12, 2007 Share Posted June 12, 2007 If your server is behind a firewall which is blocking certain ports I really cant see any way around it without going through some sort of proxy. Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272812 Share on other sites More sharing options...
btherl Posted June 12, 2007 Share Posted June 12, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272817 Share on other sites More sharing options...
smc Posted June 12, 2007 Author Share Posted June 12, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272835 Share on other sites More sharing options...
trq Posted June 12, 2007 Share Posted June 12, 2007 Look up geoip. Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272837 Share on other sites More sharing options...
smc Posted June 12, 2007 Author Share Posted June 12, 2007 Aha, perfect! Youdabest. Quote Link to comment https://forums.phpfreaks.com/topic/55187-solved-pinging-port-returns-false/#findComment-272839 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.