diff options
author | Alastair Houghton <alastair@coriolis-systems.com> | 2014-05-01 16:16:56 +0100 |
---|---|---|
committer | Alastair Houghton <alastair@coriolis-systems.com> | 2014-05-01 16:16:56 +0100 |
commit | bf5c33af471dd221518b3d6ca94f98cfaf8448c7 (patch) | |
tree | 417d97b62344434d972cb8879205014979e41cad | |
parent | 679944d3a03f22a7c2564a6cfa1af9c0721979b4 (diff) | |
download | netifaces-bf5c33af471dd221518b3d6ca94f98cfaf8448c7.tar.gz |
Fixed a silly bug I found with the test script. Added gateway output to the test script.
-rw-r--r-- | netifaces.c | 12 | ||||
-rw-r--r-- | test.py | 41 |
2 files changed, 38 insertions, 15 deletions
diff --git a/netifaces.c b/netifaces.c index 95b3003..3453f7e 100644 --- a/netifaces.c +++ b/netifaces.c @@ -1319,7 +1319,7 @@ gateways (PyObject *self) tuple = PyTuple_Pack (3, gateway, ifname, isdefault); - if (PyBool_Check (isdefault)) + if (PyObject_IsTrue (isdefault)) deftuple = PyTuple_Pack (2, gateway, ifname); Py_DECREF (gateway); @@ -1420,7 +1420,7 @@ gateways (PyObject *self) tuple = PyTuple_Pack (3, gateway, ifname, isdefault); - if (PyBool_Check (isdefault)) + if (PyObject_IsTrue (isdefault)) deftuple = PyTuple_Pack (2, gateway, ifname); Py_DECREF (gateway); @@ -1650,7 +1650,7 @@ gateways (PyObject *self) tuple = PyTuple_Pack (3, pyaddr, pyifname, isdefault); - if (PyBool_Check (isdefault)) + if (PyObject_IsTrue (isdefault)) deftuple = PyTuple_Pack (2, pyaddr, pyifname); Py_DECREF (pyaddr); @@ -1798,7 +1798,7 @@ gateways (PyObject *self) #endif tuple = PyTuple_Pack (3, pyaddr, pyifname, isdefault); - if (PyBool_Check (isdefault)) + if (PyObject_IsTrue (isdefault)) deftuple = PyTuple_Pack (2, pyaddr, pyifname); Py_DECREF (pyaddr); @@ -2026,7 +2026,7 @@ gateways (PyObject *self) tuple = PyTuple_Pack (3, pyaddr, pyifname, isdefault); - if (PyBool_Check (isdefault)) + if (PyObject_IsTrue (isdefault)) deftuple = PyTuple_Pack (2, pyaddr, pyifname); Py_DECREF (pyaddr); @@ -2205,7 +2205,7 @@ gateways (PyObject *self) tuple = PyTuple_Pack (3, pyaddr, pyifname, isdefault); - if (PyBool_Check (isdefault)) + if (PyObject_IsTrue (isdefault)) deftuple = PyTuple_Pack (2, pyaddr, pyifname); Py_DECREF (pyaddr); @@ -1,26 +1,49 @@ import netifaces -print 'Found interfaces:' +print('Found interfaces:') for iface in netifaces.interfaces(): - print ' %s' % iface + print(' %s' % iface) -print '\n' +print('') for iface in netifaces.interfaces(): allAddrs = netifaces.ifaddresses(iface) - print 'Interface %s:' % iface + print('Interface %s:' % iface) for family,addrs in allAddrs.iteritems(): fam_name = netifaces.address_families[family] - print ' Address family: %s' % fam_name + print(' Address family: %s' % fam_name) for addr in addrs: - print ' Address : %s' % addr['addr'] + print(' Address : %s' % addr['addr']) nmask = addr.get('netmask', None) if nmask: - print ' Netmask : %s' % nmask + print(' Netmask : %s' % nmask) bcast = addr.get('broadcast', None) if bcast: - print ' Broadcast: %s' % bcast + print(' Broadcast: %s' % bcast) - print '\n' + 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)) |