Skip to content

Commit

Permalink
CP, refactor arp list, closes #1344
Browse files Browse the repository at this point in the history
(cherry picked from commit 3151c87)
(cherry picked from commit 2981b66)
  • Loading branch information
AdSchellevis authored and fichtner committed Mar 1, 2017
1 parent d4933b5 commit 9f950ac
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/opnsense/scripts/OPNsense/CaptivePortal/lib/arp.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,28 @@ def _fetch_arp_table(self):
subprocess.check_call(['/usr/sbin/arp', '-an'], stdout=output_stream, stderr=subprocess.STDOUT)
output_stream.seek(0)
for line in output_stream.read().split('\n'):
if line.find('(') > -1 and line.find(')') > -1:
if line.find('expires in') > -1:
expires = line.split('expires in')[1:][0].strip().split(' ')[0]
if expires.isdigit():
expires = int(expires)
else:
expires = -1
else:
expires = -1
address = line.split(')')[0].split('(')[-1]
mac = line.split('at')[-1].split('on')[0].strip()
physical_intf = line.split('on')[-1].strip().split(' ')[0]
if address in self._arp_table:
self._arp_table[address]['intf'].append(physical_intf)
elif mac.find('incomplete') == -1:
self._arp_table[address] = {'mac': mac, 'intf': [physical_intf], 'expires': expires}
line_parts = line.split()

if len(line_parts) < 6 or line_parts[2] != 'at' or line_parts[4] != 'on':
continue

if len(line_parts[1]) < 2 or line_parts[1][0] != '(' or line_parts[1][-1] != ')':
continue

address = line_parts[1][1:-1]
physical_intf = line_parts[5]
mac = line_parts[3]
expires = -1

for index in range(len(line_parts) - 3):
if line_parts[index] == 'expires' and line_parts[index + 1] == 'in':
if line_parts[index + 2].isdigit():
expires = int(line_parts[index + 2])

if address in self._arp_table:
self._arp_table[address]['intf'].append(physical_intf)
elif mac.find('incomplete') == -1:
self._arp_table[address] = {'mac': mac, 'intf': [physical_intf], 'expires': expires}

def list_items(self):
""" return parsed arp list
Expand Down

0 comments on commit 9f950ac

Please sign in to comment.