- update route fetcher code

This commit is contained in:
Brian Martin 2015-07-31 15:34:30 -04:00
commit bb334f0ab0

View file

@ -303,16 +303,33 @@ class Traceroute(object):
def __get_network_routes(self):
"""
Gather network routes on localhost. Only grabs default gateway. Need to play around on different hosts to see what output
should be
Gather routes from netifaces module
"""
routes = []
gw = netifaces.gateways()
if 'default' in gw.keys():
routes.append( {
'default' : gw['default'][netifaces.AF_INET]
})
gws = netifaces.gateways()
for k in gws.keys():
if k == 'default':
continue
if len(gws[k]) == 1:
(ip,interface,is_gateway) = gws[k][0]
if is_gateway:
gw_name = 'default'
else: # just use the index value from netifaces
gw_name = "{0}".format(k)
routes.append({
gw_name : {
'ip_address' : ip,
'interface' : interface
}
}
)
else:
print "Error interpretting network routes. check netifaces output"
return routes