|
@@ -0,0 +1,60 @@
|
|
1
|
+import dns.resolver
|
|
2
|
+import ifcfg
|
|
3
|
+import json
|
|
4
|
+import socket
|
|
5
|
+import struct
|
|
6
|
+import sys
|
|
7
|
+import time
|
|
8
|
+
|
|
9
|
+def gateway(device):
|
|
10
|
+ with open("/proc/net/route") as fh:
|
|
11
|
+ # skip header
|
|
12
|
+ next(fh)
|
|
13
|
+ for line in fh:
|
|
14
|
+ routes = line.strip().split()
|
|
15
|
+ if routes[0] == device:
|
|
16
|
+ destination = socket.inet_ntoa(struct.pack("<L", int(routes[1], 16)))
|
|
17
|
+ if destination != "0.0.0.0":
|
|
18
|
+ continue
|
|
19
|
+ return socket.inet_ntoa(struct.pack("<L", int(routes[2], 16)))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+try:
|
|
23
|
+ DEVICE = sys.argv[1]
|
|
24
|
+except IndexError:
|
|
25
|
+ print("You need to give the device name as first argument")
|
|
26
|
+ sys.exit()
|
|
27
|
+
|
|
28
|
+HRN = { # Human Readable Name
|
|
29
|
+ 'MAC': 'ether',
|
|
30
|
+ 'MTU': 'mtu',
|
|
31
|
+ 'IP': 'inet',
|
|
32
|
+ 'Netmask': 'netmask',
|
|
33
|
+}
|
|
34
|
+
|
|
35
|
+try:
|
|
36
|
+ info = ifcfg.interfaces()[DEVICE]
|
|
37
|
+except KeyError:
|
|
38
|
+ print("Unknown device:", DEVICE)
|
|
39
|
+ sys.exit(1)
|
|
40
|
+try:
|
|
41
|
+ dns_resolver = dns.resolver.Resolver()
|
|
42
|
+except dns.resolver.NoResolverConfiguration:
|
|
43
|
+ dns_server = []
|
|
44
|
+else:
|
|
45
|
+ dns_server = dns_resolver.nameservers
|
|
46
|
+
|
|
47
|
+print('+' + 27 * '-' + '+')
|
|
48
|
+print("|%9s: %s" % ('Device', DEVICE) + (16 - len(DEVICE)) * ' ' + '|')
|
|
49
|
+print('+' + 27 * '-' + '+')
|
|
50
|
+for name in HRN:
|
|
51
|
+ print("%10s: %s" % (name, info[HRN[name]]))
|
|
52
|
+print("%10s: %s" % ('Gateway', gateway(DEVICE)))
|
|
53
|
+
|
|
54
|
+try:
|
|
55
|
+ print("%10s: %s" % ("Domain", socket.getfqdn().split('.', 1)[1]))
|
|
56
|
+except IndexError:
|
|
57
|
+ print("%10s: None" % "Domain")
|
|
58
|
+for i, dns in enumerate(dns_server):
|
|
59
|
+ print("%10s: %s" % ("DNS_%d" % (i + 1), dns))
|
|
60
|
+
|