2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-30 12:07:09 +00:00

better support for ping under a non-root account

git-svn-id: https://svn.fhem.de/fhem/trunk@2659 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
markusbloch 2013-02-07 22:08:38 +00:00
parent b241d996c1
commit 5739dc4ba4

View File

@ -30,7 +30,6 @@ package main;
use strict; use strict;
use warnings; use warnings;
use Blocking; use Blocking;
use Net::Ping;
use Time::HiRes qw(gettimeofday sleep); use Time::HiRes qw(gettimeofday sleep);
use DevIo; use DevIo;
@ -356,24 +355,32 @@ PRESENCE_DoLocalPingScan($$)
my ($string) = @_; my ($string) = @_;
my ($name, $device) = split("\\|", $string); my ($name, $device) = split("\\|", $string);
my $pingtool = Net::Ping->new("icmp");
my $retcode; my $retcode;
my $return; my $return;
my $temp;
if($^O =~ m/Win/)
{
eval "require Net::Ping;";
my $pingtool = Net::Ping->new("syn");
if($pingtool) if($pingtool)
{ {
$retcode = $pingtool->ping($device, 5); $retcode = $pingtool->ping($device, 5);
$return = "$name|".($retcode ? "present" : "absent"); $return = "$name|".($retcode ? "present" : "absent");
} }
else else
{ {
$return = "$name|error|Could not create a Net::Ping object."; $return = "$name|error|Could not create a Net::Ping object.";
} }
return $return; }
else
{
$temp = qx(ping -c 4 $device);
$return = "$name|".($temp =~ /\d+ bytes from/ ? "present" : "absent");
}
return $return;
} }