- 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):
|
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
|
Gather routes from netifaces module
|
||||||
should be
|
|
||||||
"""
|
"""
|
||||||
routes = []
|
routes = []
|
||||||
|
|
||||||
gw = netifaces.gateways()
|
gws = netifaces.gateways()
|
||||||
if 'default' in gw.keys():
|
for k in gws.keys():
|
||||||
routes.append( {
|
if k == 'default':
|
||||||
'default' : gw['default'][netifaces.AF_INET]
|
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
|
return routes
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue