Created
April 30, 2012 08:09
-
-
Save nckltcha/2556441 to your computer and use it in GitHub Desktop.
Check IPs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * First, we declare an array of domains to check. Each array is for a domain that we want to check, and the port that we want to check. | |
| * The third value is how long fsockopen should wait before timing out. | |
| */ | |
| $ports = array ( | |
| array('192.168.0.1', 80, 1,'Router'), | |
| array('192.168.0.7', 90, 1,'Self'), | |
| array('www.yahoo.com', 80, 1,'google'), | |
| array('www.sitethatdoesnotexist.com', 80, 1,'nothing') | |
| ); | |
| /** | |
| * Now we loop through the array and check each domain | |
| */ | |
| foreach ($ports as $port) { | |
| /** | |
| * fsockopen takes as arguments the domain name, the port, a variable to hold the error number and error string if an error should occur, and finally the timeout value. | |
| */ | |
| $fp = @fsockopen($port[0], $port[1], $errno, $errstr, $port[2]); | |
| /** | |
| * If the resource returned by fsockopen is not set, then we report that the site is down and not taking connections | |
| */ | |
| if (!$fp) { | |
| echo "{$port[3]} ({$port[0]}) is down: $errstr ($errno)<br />\n"; | |
| /** | |
| * Otherwise we report that the site is up | |
| */ | |
| } else { | |
| echo "{$port[3]} ({$port[0]}) is up<br/>\n"; | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment