- update route fetcher code
This commit is contained in:
parent
5c837d7e00
commit
bb334f0ab0
1 changed files with 24 additions and 7 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue