-
Notifications
You must be signed in to change notification settings - Fork 0
/
pingtool.php
57 lines (53 loc) · 1.54 KB
/
pingtool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!--
=== Note: ==========================================
THIS WILL TAKE A LONG TIME TO LOAD! It has to scan
through 255 IPs to check if they are online. If you
have a bad internet connection or an extremely weak
PC, do *not* use this tool!
-->
<?php
set_time_limit(0);
$hostname = "http://".gethostbyname(gethostname());
$ip_arr = explode(".", $hostname);
array_pop($ip_arr);
$host = implode(".", $ip_arr).".";
?>
<p>You are <b><?= $hostname; ?></b></p>
<button id="hideOffline">Toggle offline</button><br>
<table>
<thead>
<th>Name / address</th>
<th>Status</th>
</thead>
<tbody>
<?php
for ($i=0; $i < 30; $i++) {
$cinit = curl_init($host.$i);
curl_setopt($cinit, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($cinit, CURLOPT_HEADER, true);
curl_setopt($cinit, CURLOPT_NOBODY, true);
curl_setopt($cinit, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($cinit);
curl_close($cinit);
$pcname = gethostbyaddr(str_replace("http://", "", $host.$i));
if ($response) {
echo "<tr class='online'>
<td><a href='".$host.$i."' target='_blank'>".$pcname."</a></td>
<td style='color:green;'>Online</td>
</tr>";
} else {
echo "<tr class='offline'>
<td>".$host."<b>".$i."</b></td>
<td style='color:red';'>Offline</td>
</tr>";
}
}
?>
</tbody>
</table>
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$("#hideOffline").click(function() {
$(".offline").toggle();
});
</script>