diff --git a/netst b/netst new file mode 100755 index 0000000..4eef6eb --- /dev/null +++ b/netst @@ -0,0 +1,6 @@ +#!/bin/bash +# +BASEPATH=$(dirname $0) + +$BASEPATH/venv/bin/python $BASEPATH/netst.py $* + diff --git a/netst.py b/netst.py new file mode 100644 index 0000000..9d201bd --- /dev/null +++ b/netst.py @@ -0,0 +1,67 @@ +import dns.resolver +import ifcfg +import json +import socket +import struct +import sys +import time + +interfaces = ifcfg.interfaces() + +def exit_device(): + print("Possible devices:", ", ".join(interfaces.keys())) + sys.exit(1) + + +def gateway(device): + with open("/proc/net/route") as fh: + # skip header + next(fh) + for line in fh: + routes = line.strip().split() + if routes[0] == device: + destination = socket.inet_ntoa(struct.pack("