Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
3d4743dd
Commit
3d4743dd
authored
Oct 14, 2015
by
Ad Schellevis
Committed by
Franco Fichtner
Oct 16, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(captiveportal, new) add get_address_by_mac to arp lib
(cherry picked from commit
7ef601b2
)
parent
bcd1b5d1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
1 deletion
+23
-1
arp.py
src/opnsense/scripts/OPNsense/CaptivePortal/lib/arp.py
+23
-1
No files found.
src/opnsense/scripts/OPNsense/CaptivePortal/lib/arp.py
View file @
3d4743dd
...
@@ -52,13 +52,21 @@ class ARP(object):
...
@@ -52,13 +52,21 @@ class ARP(object):
output_stream
.
seek
(
0
)
output_stream
.
seek
(
0
)
for
line
in
output_stream
.
read
()
.
split
(
'
\n
'
):
for
line
in
output_stream
.
read
()
.
split
(
'
\n
'
):
if
line
.
find
(
'('
)
>
-
1
and
line
.
find
(
')'
)
>
-
1
:
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
]
address
=
line
.
split
(
')'
)[
0
]
.
split
(
'('
)[
-
1
]
mac
=
line
.
split
(
'at'
)[
-
1
]
.
split
(
'on'
)[
0
]
.
strip
()
mac
=
line
.
split
(
'at'
)[
-
1
]
.
split
(
'on'
)[
0
]
.
strip
()
physical_intf
=
line
.
split
(
'on'
)[
-
1
]
.
strip
()
.
split
(
' '
)[
0
]
physical_intf
=
line
.
split
(
'on'
)[
-
1
]
.
strip
()
.
split
(
' '
)[
0
]
if
address
in
self
.
_arp_table
:
if
address
in
self
.
_arp_table
:
self
.
_arp_table
[
address
][
'intf'
]
.
append
(
physical_intf
)
self
.
_arp_table
[
address
][
'intf'
]
.
append
(
physical_intf
)
else
:
else
:
self
.
_arp_table
[
address
]
=
{
'mac'
:
mac
,
'intf'
:
[
physical_intf
]}
self
.
_arp_table
[
address
]
=
{
'mac'
:
mac
,
'intf'
:
[
physical_intf
]
,
'expires'
:
expires
}
def
list_items
(
self
):
def
list_items
(
self
):
""" return parsed arp list
""" return parsed arp list
...
@@ -75,3 +83,17 @@ class ARP(object):
...
@@ -75,3 +83,17 @@ class ARP(object):
return
self
.
_arp_table
[
address
]
return
self
.
_arp_table
[
address
]
else
:
else
:
return
None
return
None
def
get_address_by_mac
(
self
,
address
):
""" search arp entry by mac address, most recent arp entry
:param address: ip address
:return: dict or None (if not found)
"""
result
=
None
for
item
in
self
.
_arp_table
:
if
self
.
_arp_table
[
item
][
'mac'
]
==
address
:
if
result
is
None
:
result
=
item
elif
self
.
_arp_table
[
result
][
'expires'
]
<
self
.
_arp_table
[
item
][
'expires'
]:
result
=
item
return
result
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment