Browse Source

change how we get ips

windows
Florian N 12 years ago
parent
commit
aabfc60c9b
  1. 12
      main/views.py
  2. 5
      templates/main.html

12
main/views.py

@ -62,18 +62,16 @@ 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(" ip addr | grep -A3 'state UP' | awk '{printf \"%s,\",$2}'|awk -F, '{print $1, $2, $3}'")
data = pipe.read().strip().split('\n')
pipe.close()
data = [n for n in data if not n.startswith(('lo', '127'))]
data = [i.split(None, 2) for i in data]
data = [i.split(None, 3) for i in data]
for e in data:
if len(e) > 2:
itf = dict(zip([iter(e[0])]))
if len(e) > 3:
itf = dict(zip([iter(e[0].strip(':'))]))
else:
itf = [e[0]]
itf = [e[0].strip(':')]
ips = {'interface': itf, 'itfip': data}

5
templates/main.html

@ -214,8 +214,9 @@
<table class="table table-hover table-condensed table-bordered">
<thead>
<tr>
<th>Interface</th>
<th>Intf</th>
<th>IP</th>
<th>Mac</th>
</tr>
</thead>
<tbody id="get-ips">
@ -368,7 +369,7 @@ dashboard.getIps = function() {
$.getJSON('/info/getips/', function(data) {
var tr='';
$.each( data, function( index, item){
tr+='<tr><td>'+item[0]+'</td><td>'+item[1]+'</td></tr>';
tr+='<tr><td>'+item[0]+'</td><td>'+item[2]+'</td><td>'+item[1]+'</td></tr>';
})
tr+='';
$("#get-ips").html( tr );

Loading…
Cancel
Save