Fix error whith arping path
This commit is contained in:
+13
-5
@@ -25,6 +25,7 @@ import signal
|
|||||||
|
|
||||||
from iniparse import RawConfigParser
|
from iniparse import RawConfigParser
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
from distutils.spawn import find_executable
|
||||||
|
|
||||||
usage="""\
|
usage="""\
|
||||||
%prog -c configfile action
|
%prog -c configfile action
|
||||||
@@ -105,16 +106,23 @@ ARPING 192.168.149.254
|
|||||||
"""
|
"""
|
||||||
ARPING1 = re.compile(r'bytes from (?P<mac>\S+).*time=(?P<rtt>[0-9.]*) (?P<unit>.*)')
|
ARPING1 = re.compile(r'bytes from (?P<mac>\S+).*time=(?P<rtt>[0-9.]*) (?P<unit>.*)')
|
||||||
ARPING2 = re.compile(r'reply from.*\[(?P<mac>\S+)\]\s+(?P<rtt>[0-9.]*)(?P<unit>.*)')
|
ARPING2 = re.compile(r'reply from.*\[(?P<mac>\S+)\]\s+(?P<rtt>[0-9.]*)(?P<unit>.*)')
|
||||||
|
ARPING_PATH = find_executable('arping')
|
||||||
(returncode,output) = run('/usr/sbin/arping -c{ping_count} -i{device} {target_ip}'.format(
|
if ARPING_PATH == None:
|
||||||
|
raise Exception('No arping command found')
|
||||||
|
elif "/usr/bin/arping" in ARPING_PATH:
|
||||||
|
(returncode,output) = run('arping -c{ping_count} -I{device} {target_ip}'.format(
|
||||||
ping_count = ping_count,
|
ping_count = ping_count,
|
||||||
device = device,
|
device = device,
|
||||||
target_ip = target_ip,
|
target_ip = target_ip,
|
||||||
))
|
))
|
||||||
|
|
||||||
packets = [p.groupdict() for p in ARPING1.finditer(output)]
|
|
||||||
if not packets:
|
|
||||||
packets = [p.groupdict() for p in ARPING2.finditer(output)]
|
packets = [p.groupdict() for p in ARPING2.finditer(output)]
|
||||||
|
elif "/usr/sbin/arping" in ARPING_PATH:
|
||||||
|
(returncode,output) = run('arping -c{ping_count} -i{device} {target_ip}'.format(
|
||||||
|
ping_count = ping_count,
|
||||||
|
device = device,
|
||||||
|
target_ip = target_ip,
|
||||||
|
))
|
||||||
|
packets = [p.groupdict() for p in ARPING1.finditer(output)]
|
||||||
result = {}
|
result = {}
|
||||||
if packets:
|
if packets:
|
||||||
result['mac'] = packets[-1]['mac']
|
result['mac'] = packets[-1]['mac']
|
||||||
|
|||||||
Reference in New Issue
Block a user