- added interface info
This commit is contained in:
parent
1c5a84b739
commit
a468c1138d
1 changed files with 18 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
import requests
|
import requests
|
||||||
|
import netifaces
|
||||||
|
|
||||||
USER_AGENT = "traceroute/1.0 (+https://github.com/ayeowch/traceroute)"
|
USER_AGENT = "traceroute/1.0 (+https://github.com/ayeowch/traceroute)"
|
||||||
|
|
||||||
|
|
@ -39,6 +40,7 @@ class Traceroute(object):
|
||||||
if self.country == 'LO':
|
if self.country == 'LO':
|
||||||
self.local_mode = True
|
self.local_mode = True
|
||||||
self.pub_ip = self._lookup_public_ip()
|
self.pub_ip = self._lookup_public_ip()
|
||||||
|
self.ifaces = self._get_network_interface_info()
|
||||||
else:
|
else:
|
||||||
self.local_mode = False
|
self.local_mode = False
|
||||||
|
|
||||||
|
|
@ -91,6 +93,7 @@ class Traceroute(object):
|
||||||
report_structure['hops'] = self.hops
|
report_structure['hops'] = self.hops
|
||||||
if self.local_mode:
|
if self.local_mode:
|
||||||
report_structure['pub_ip'] = self.pub_ip
|
report_structure['pub_ip'] = self.pub_ip
|
||||||
|
report_structure['ifaces'] = self.ifaces
|
||||||
|
|
||||||
return report_structure
|
return report_structure
|
||||||
|
|
||||||
|
|
@ -108,6 +111,21 @@ class Traceroute(object):
|
||||||
else:
|
else:
|
||||||
return 'Unable to determine IP'
|
return 'Unable to determine IP'
|
||||||
|
|
||||||
|
def _get_network_interface_info(self):
|
||||||
|
iface_list = []
|
||||||
|
for i in netifaces.interfaces():
|
||||||
|
addr = netifaces.ifaddresses(i)
|
||||||
|
|
||||||
|
# only retrieve interfaces that are active
|
||||||
|
if netifaces.AF_INET in addr.keys():
|
||||||
|
iface_list.append( {i : {
|
||||||
|
'ip_address' : addr[netifaces.AF_INET][0]['addr'],
|
||||||
|
'mac' : addr[netifaces.AF_LINK][0]['addr']
|
||||||
|
}})
|
||||||
|
|
||||||
|
return iface_list
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue