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