forked from pool/python-netifaces
Accepting request 705219 from home:pgajdos
- version update to 0.10.9 * Fixed a bug that in certain circumstances could lead to an infinite loop in netifaces.gateways() (thanks asomers). * Fixed a memory management bug in an error path (thanks NicoPy). - created a small test OBS-URL: https://build.opensuse.org/request/show/705219 OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-netifaces?expand=0&rev=23
This commit is contained in:
committed by
Git OBS Bridge
parent
b81b5df8e7
commit
9f1a871ff4
50
test.py
Normal file
50
test.py
Normal file
@@ -0,0 +1,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))
|
Reference in New Issue
Block a user