-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.php
More file actions
47 lines (38 loc) · 1.08 KB
/
Copy pathcli.php
File metadata and controls
47 lines (38 loc) · 1.08 KB
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
<?php
require __DIR__ . '/config.php';
require __DIR__ . '/database.php';
require __DIR__ . '/ping.php';
$command = $argv[1] ?? '';
if ($command === 'ping') {
exit(runPingCommand(array_slice($argv, 2)));
}
fwrite(STDERR, "Usage: php cli.php ping [1-254|DEBUG]\n");
exit(2);
function runPingCommand($args) {
global $network, $interface, $myself;
$arg = $args[0] ?? '';
$debugEnv = getenv('DEBUG');
$debug = $arg !== '' || ($debugEnv !== false && $debugEnv !== '');
$from = 1;
$to = 254;
if ($arg !== '' && $arg !== 'DEBUG') {
if (!ctype_digit($arg) || intval($arg) < 1 || intval($arg) > 254) {
fwrite(STDERR, "Usage: php cli.php ping [1-254|DEBUG]\n");
return 2;
}
$from = intval($arg);
$to = $from;
}
$targets = array();
for ($i = $from; $i <= $to; $i++)
$targets[$i] = $network . "." . $i;
$hosts = pingHosts($targets, $interface ?? '', array_filter(array_unique(array(
getenv('IP') ?: '',
$myself ?? ''
))));
if ($debug) {
foreach ($hosts as $host)
echo $host["ip"] . " " . $host["status"] . PHP_EOL;
}
return 0;
}