Browse Source

get interfaces

windows
Florian N 12 years ago
parent
commit
db8eb15dc8
  1. 10
      main/views.py
  2. 5
      usage/views.py

10
main/views.py

@ -62,15 +62,19 @@ def get_ipaddress():
Get the IP Address
"""
try:
pipe = os.popen("/sbin/ifconfig |" + "grep -B1 'inet addr' |" + "awk '{ if ( $1 == \"inet\" ) { print $2 } else if ( $2 == \"Link\" ) { printf \"%s:\",$1 } }' |" + "awk -F: '{ print $1, $3 }'")
pipe = os.popen("/sbin/ifconfig |" + "grep -B1 'inet addr' |" + "awk '{ if ( $1 == \"inet\" ) { print $2 } else if ( $2 == \"Link\" ) { printf \"%s:\",$1 } }' |" + " awk -F: '{ print $1, $3 }'")
data = pipe.read().strip().split('\n')
pipe.close()
data = [n for n in data if not n.startswith(('lo', '127'))]
itf = dict(zip(*[iter(data)] * 2))
data = [i.split(None, 2) for i in data]
for e in data:
if len(e) > 2:
itf = dict(zip([iter(e[0])]))
else:
itf = [e[0]]
ips = {'interface': itf, 'itfip': data}
data = ips

5
usage/views.py

@ -251,7 +251,10 @@ def gettraffic(request):
cookie_traffic = {}
try:
traffic = get_traffic('eth0')
intf = get_ipaddress()
intf = intf['interface'][0]
traffic = get_traffic(intf)
except Exception:
traffic = 0

Loading…
Cancel
Save