Skip to content

Instantly share code, notes, and snippets.

@hplc
Created October 22, 2019 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hplc/bea90e8934c3c19304f8c79850fc18b4 to your computer and use it in GitHub Desktop.
Save hplc/bea90e8934c3c19304f8c79850fc18b4 to your computer and use it in GitHub Desktop.
Check a bunch of web servers' online status.
<!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