This repository has been archived by the owner on Jun 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
test.py
50 lines (41 loc) · 1.43 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import netifaces
print('Found interfaces:')
for iface in netifaces.interfaces():
print(' %s' % iface)
print('')
for iface in netifaces.interfaces():
allAddrs = netifaces.ifaddresses(iface)
print('Interface %s:' % iface)
for family in allAddrs:
addrs = allAddrs[family]
fam_name = netifaces.address_families[family]
print(' Address family: %s' % fam_name)
for addr in addrs:
print(' Address : %s' % addr['addr'])
nmask = addr.get('netmask', None)
if nmask:
print(' Netmask : %s' % nmask)
bcast = addr.get('broadcast', None)
if bcast:
print(' Broadcast: %s' % bcast)
print('')
print('Found gateways:')
gateway_info = netifaces.gateways()
for family in gateway_info:
if family == 'default':
continue
fam_name = netifaces.address_families[family]
print(' Family: %s' % fam_name)
for gateway,interface,default in gateway_info[family]:
if default:
def_text = ', default'
else:
def_text = ''
print(' %s (via %s%s)' % (gateway, interface, def_text))
print('')
print('Default gateways:')
default_gateways = gateway_info['default']
for family in default_gateways:
fam_name = netifaces.address_families[family]
gateway, interface = default_gateways[family]
print(' %s: %s (via %s)' % (fam_name, gateway, interface))