Created
October 22, 2019 09:58
-
-
Save hplc/bea90e8934c3c19304f8c79850fc18b4 to your computer and use it in GitHub Desktop.
Check a bunch of web servers' online status.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>16CNetG5-2</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
</head> | |
<body> | |
<?php | |
/* Contents of 16CNetG5-2.csv file like this: | |
01-林增良,10.3.22.126 | |
02-李锦放,10.3.22.148 | |
03-陈晓彬,10.3.22.104 | |
...... | |
*/ | |
$handle = fopen('16CNetG5-2.csv','r'); | |
while ($record = fgetcsv($handle)) { | |
// var_dump($record); | |
if (stest($record[1], 80)) { | |
// $color = 'green'; | |
$color = 'whitesmoke'; | |
} else { | |
$color = 'palevioletred'; | |
} | |
echo "<div style=\"margin: 5px; background-color: $color; font-size: 1.5em;\">$record[0] <a href=\"http://$record[1]\" target=\"_blank\">$record[1]</a></div>"; | |
} | |
// Check TCP port, timeout=0.1s. | |
function stest($ip, $portt) { | |
$fp = @fsockopen($ip, $portt, $errno, $errstr, 0.1); | |
if (!$fp) { | |
return false; | |
} else { | |
fclose($fp); | |
return true; | |
} | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment