Exception handling for wrong device
This commit is contained in:
parent
4a5ea44daa
commit
b44cfef41d
@ -6,6 +6,13 @@ import struct
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
interfaces = ifcfg.interfaces()
|
||||||
|
|
||||||
|
def exit_device():
|
||||||
|
print("Possible devices:", ", ".join(interfaces.keys()))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def gateway(device):
|
def gateway(device):
|
||||||
with open("/proc/net/route") as fh:
|
with open("/proc/net/route") as fh:
|
||||||
# skip header
|
# skip header
|
||||||
@ -22,8 +29,8 @@ def gateway(device):
|
|||||||
try:
|
try:
|
||||||
DEVICE = sys.argv[1]
|
DEVICE = sys.argv[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print("You need to give the device name as first argument")
|
print("You need to give the device name as first argument!\n")
|
||||||
sys.exit()
|
exit_device()
|
||||||
|
|
||||||
HRN = { # Human Readable Name
|
HRN = { # Human Readable Name
|
||||||
'MAC': 'ether',
|
'MAC': 'ether',
|
||||||
@ -33,10 +40,10 @@ HRN = { # Human Readable Name
|
|||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
info = ifcfg.interfaces()[DEVICE]
|
info = interfaces[DEVICE]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print("Unknown device:", DEVICE)
|
print("Unknown device:", DEVICE, "\n")
|
||||||
sys.exit(1)
|
exit_device()
|
||||||
try:
|
try:
|
||||||
dns_resolver = dns.resolver.Resolver()
|
dns_resolver = dns.resolver.Resolver()
|
||||||
except dns.resolver.NoResolverConfiguration:
|
except dns.resolver.NoResolverConfiguration:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user