Mac compatibility achieved
This commit is contained in:
parent
9f20431887
commit
fafe321788
27
ping.inc.py
27
ping.inc.py
|
@ -67,7 +67,7 @@ class Pinger:
|
||||||
pingout = Util.doPing(target)
|
pingout = Util.doPing(target)
|
||||||
ssidout = Util.getSsid()
|
ssidout = Util.getSsid()
|
||||||
|
|
||||||
print json.dumps({'ssid': ssidout, 'loss': int(pingout)})
|
print json.dumps({'ssid': ssidout, 'loss': float(pingout)})
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Print welcome message
|
# Print welcome message
|
||||||
|
@ -92,8 +92,13 @@ class Util:
|
||||||
out, error = ssid.communicate()
|
out, error = ssid.communicate()
|
||||||
m = re.search(r'yes:(.*)', out)
|
m = re.search(r'yes:(.*)', out)
|
||||||
result = m.group(1)
|
result = m.group(1)
|
||||||
elif platform.system() == "Macintosh":
|
elif platform.system() == "Darwin":
|
||||||
foo
|
ssid = subprocess.Popen(["/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport","-I"],
|
||||||
|
stdout = subprocess.PIPE,
|
||||||
|
stderr = subprocess.PIPE
|
||||||
|
)
|
||||||
|
out, error = ssid.communicate()
|
||||||
|
result = out
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -112,8 +117,20 @@ class Util:
|
||||||
pingout = -1
|
pingout = -1
|
||||||
else:
|
else:
|
||||||
pingout = m.group(1)
|
pingout = m.group(1)
|
||||||
elif platform.system() == "Macintosh":
|
elif platform.system() == "Darwin": # Macintosh
|
||||||
foo
|
ping = subprocess.Popen(
|
||||||
|
["ping", "-c", "5", target],
|
||||||
|
stdout = subprocess.PIPE,
|
||||||
|
stderr = subprocess.PIPE
|
||||||
|
)
|
||||||
|
out, error = ping.communicate()
|
||||||
|
# print out
|
||||||
|
m = re.search(r' ([0-9\.]+)% packet loss', out, re.MULTILINE) # (^rtt .*$)|
|
||||||
|
# print m.groups()
|
||||||
|
if error or m.group(1) == 100:
|
||||||
|
pingout = -1
|
||||||
|
else:
|
||||||
|
pingout = m.group(1)
|
||||||
return pingout
|
return pingout
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue
Block a user