Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import platform
- import shlex
- from subprocess import call, DEVNULL
- from netifaces import gateways, AF_INET
- def gateway_alive(nic="wlan0"):
- system = platform.system()
- gws = gateways().get(AF_INET, [])
- for ip, interface, default in gws:
- if interface == nic:
- if system == "Windows":
- cmd = shlex.split(f"ping -n 1 -w 1 {ip}")
- elif system == "Linux":
- cmd = shlex.split(f"ping -c1 -W1 {ip}")
- else:
- raise RuntimeError(f"{system} is not supported.")
- if call(cmd, stdout=DEVNULL, stderr=DEVNULL) == 0:
- return True
- else:
- return False
- return False
Add Comment
Please, Sign In to add comment