Fix error whith arping path

This commit is contained in:
Steven Samson
2014-04-23 10:32:53 +02:00
parent 5e87ad3ed1
commit 925c2440d9
+13 -5
View File
@@ -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']