Open Port, Port Forwarding Test Tool
July 1, 2008 – 9:00 pmI work with a lot of NAT routers. Every brand imaginable, D-link, Linksys, odd jobs that ISPs supply, you name it. Sometimes it can be a pain to get them to forward ports properly, it can be even more of a pain to test if it is working. I wrote a script that can test if the forwarding is set up properly. It is so simple, and yet so much of a god send.
Here is the guts of the source:
function connect_port($port) { $host = $_SERVER['REMOTE_ADDR']; $fp = fsockopen($host, $port, $errno, $errstr, 5); if (!$fp) { $result = "<strong><span style="color: red;">Could not connect to $port on $host ($errstr). Bummer.</span></strong>"; if(preg_match($errstr, "Connection refused")) { $result .= "It appears you have the port forwarding set up, but nothing is answering on port $port. Possible Causes: <ul> <li> Did you forget to start some software on your computer?</li> <li> Is your router forwarding to the correct IP address on your local network?</li> </ul> "; } else { $result .= " Possible Causes: <ul> <li> Your firewall isn't forwarding port $port.</li> <li> Your ISP is blocking port $port.</li> </ul> "; } } else { $result = "<strong><span style="color: green;">Connect to port $port on $host OK!</span></strong>\n"; } fclose($fp); return($result); }
Sorry, comments for this entry are closed at this time.