Open goldjunge4 opened 2 months ago
I have the same problem.
Easiest way: try-catch
try {
$command = (new PingCommandBuilder('x.x.x.x'));
// Pass the PingCommand instance to Ping and run...
$ping = (new Ping($command))->run();
} catch (Exception $e) {
Log::error($e);
}
I'll try to solve that problem. In touch!
Works for me on Ubuntu.
try {
$monitoring = (new PingCommandBuilder('$ipAddress'))
->count(2)
->interval(1)
->ttl(128);
$ping = (new Ping($monitoring))->run();
//looking for response
if ($ping->host_status == 'Ok') {
Log::info('Host is online!');
} else {
//no response
Log::error('Host is unreachable');
}
} catch (Exception $e) {
//0 errors happened. Undefined array key 1 exception not shown.
Log::error('Error! Host is unreachable'); // or Log::error($e);
}
Tested IP range: 192.168.0.1/24
Needs more tests, ex. offline gateway. Hope, it solve this problem.
----- edit ----- Tested more.
Ok, fine... I tried ping with ->count(2). If count is less than 3 array is not returned:
https://github.com/angelcamposm/ping/blob/b0a209005b9db96bbb9a68703cdd5b93d454c448/src/Ping.php#L98
Sooo.... in my opinion, try-catch is best way to avoid bug. Exception = host offline.
Hello
i am running your package on an Ubuntu Server and it is running perfect if the host is reachable, but if the host is unreachable i get following Exception:
I am working on Laravel 11 and run the command:
Do you know what i can do the get a correct result on unreachable devices?
Thanks