netst added to my bin folder
This commit is contained in:
parent
d5f22f1a49
commit
4a5ea44daa
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
|
*/venv
|
||||||
|
|
||||||
# ---> Linux
|
# ---> Linux
|
||||||
*~
|
*~
|
||||||
|
|
||||||
|
6
netst
Executable file
6
netst
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
BASEDIR=$(dirname $0)
|
||||||
|
|
||||||
|
$BASEDIR/netst.src/venv/bin/python $BASEDIR/netst.src/netst.py $*
|
||||||
|
|
60
netst.src/netst.py
Normal file
60
netst.src/netst.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import dns.resolver
|
||||||
|
import ifcfg
|
||||||
|
import json
|
||||||
|
import socket
|
||||||
|
import struct
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
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("<L", int(routes[1], 16)))
|
||||||
|
if destination != "0.0.0.0":
|
||||||
|
continue
|
||||||
|
return socket.inet_ntoa(struct.pack("<L", int(routes[2], 16)))
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
DEVICE = sys.argv[1]
|
||||||
|
except IndexError:
|
||||||
|
print("You need to give the device name as first argument")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
HRN = { # Human Readable Name
|
||||||
|
'MAC': 'ether',
|
||||||
|
'MTU': 'mtu',
|
||||||
|
'IP': 'inet',
|
||||||
|
'Netmask': 'netmask',
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
info = ifcfg.interfaces()[DEVICE]
|
||||||
|
except KeyError:
|
||||||
|
print("Unknown device:", DEVICE)
|
||||||
|
sys.exit(1)
|
||||||
|
try:
|
||||||
|
dns_resolver = dns.resolver.Resolver()
|
||||||
|
except dns.resolver.NoResolverConfiguration:
|
||||||
|
dns_server = []
|
||||||
|
else:
|
||||||
|
dns_server = dns_resolver.nameservers
|
||||||
|
|
||||||
|
print('+' + 27 * '-' + '+')
|
||||||
|
print("|%9s: %s" % ('Device', DEVICE) + (16 - len(DEVICE)) * ' ' + '|')
|
||||||
|
print('+' + 27 * '-' + '+')
|
||||||
|
for name in HRN:
|
||||||
|
print("%10s: %s" % (name, info[HRN[name]]))
|
||||||
|
print("%10s: %s" % ('Gateway', gateway(DEVICE)))
|
||||||
|
|
||||||
|
try:
|
||||||
|
print("%10s: %s" % ("Domain", socket.getfqdn().split('.', 1)[1]))
|
||||||
|
except IndexError:
|
||||||
|
print("%10s: None" % "Domain")
|
||||||
|
for i, dns in enumerate(dns_server):
|
||||||
|
print("%10s: %s" % ("DNS_%d" % (i + 1), dns))
|
||||||
|
|
3
netst.src/requirements.txt
Normal file
3
netst.src/requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ifcfg
|
||||||
|
dnspython
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user