Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
36c72d4a
Commit
36c72d4a
authored
15 years ago
by
Dirk Loss
Browse files
Options
Downloads
Patches
Plain Diff
Adapted Windows-specific getmacbyip() to changes in the original
parent
cee0b5cc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scapy/arch/windows/__init__.py
+14
-8
14 additions, 8 deletions
scapy/arch/windows/__init__.py
with
14 additions
and
8 deletions
scapy/arch/windows/__init__.py
+
14
−
8
View file @
36c72d4a
...
@@ -263,17 +263,24 @@ def read_routes6():
...
@@ -263,17 +263,24 @@ def read_routes6():
return
[]
return
[]
def
getmacbyip
(
ip
,
chainCC
=
0
):
def
getmacbyip
(
ip
,
chainCC
=
0
):
"""
Return MAC address corresponding to a given IP address
"""
if
isinstance
(
ip
,
Net
):
ip
=
iter
(
ip
).
next
()
tmp
=
map
(
ord
,
inet_aton
(
ip
))
if
(
tmp
[
0
]
&
0xf0
)
==
0xe0
:
# mcast @
return
"
01:00:5e:%.2x:%.2x:%.2x
"
%
(
tmp
[
1
]
&
0x7f
,
tmp
[
2
],
tmp
[
3
])
iff
,
a
,
gw
=
conf
.
route
.
route
(
ip
)
iff
,
a
,
gw
=
conf
.
route
.
route
(
ip
)
if
iff
==
"
lo
"
:
if
(
(
iff
==
LOOPBACK_NAME
)
or
(
ip
==
conf
.
route
.
get_if_bcast
(
iff
))
)
:
return
"
ff:ff:ff:ff:ff:ff
"
return
"
ff:ff:ff:ff:ff:ff
"
#
w
indows uses local
ip
instead of 0.0.0.0 to represent locally reachable addresses
#
W
indows uses local
IP
instead of 0.0.0.0 to represent locally reachable addresses
ifip
=
str
(
pcapdnet
.
dnet
.
intf
().
get
(
iff
)[
'
addr
'
])
ifip
=
str
(
pcapdnet
.
dnet
.
intf
().
get
(
iff
)[
'
addr
'
])
if
gw
!=
ifip
.
split
(
'
/
'
)[
0
]:
if
gw
!=
ifip
.
split
(
'
/
'
)[
0
]:
ip
=
gw
ip
=
gw
if
arp_cache
.
has_key
(
ip
):
mac
,
timeout
=
arp_cache
[
ip
]
mac
=
conf
.
netcache
.
arp_cache
.
get
(
ip
)
if
timeout
and
(
time
.
time
()
-
timeout
<
ARPTIMEOUT
):
if
mac
:
return
mac
return
mac
res
=
srp1
(
Ether
(
dst
=
ETHER_BROADCAST
)
/
ARP
(
op
=
"
who-has
"
,
pdst
=
ip
),
res
=
srp1
(
Ether
(
dst
=
ETHER_BROADCAST
)
/
ARP
(
op
=
"
who-has
"
,
pdst
=
ip
),
type
=
ETH_P_ARP
,
type
=
ETH_P_ARP
,
iface
=
iff
,
iface
=
iff
,
...
@@ -281,10 +288,9 @@ def getmacbyip(ip, chainCC=0):
...
@@ -281,10 +288,9 @@ def getmacbyip(ip, chainCC=0):
verbose
=
0
,
verbose
=
0
,
chainCC
=
chainCC
,
chainCC
=
chainCC
,
nofilter
=
1
)
nofilter
=
1
)
if
res
is
not
None
:
if
res
is
not
None
:
mac
=
res
.
payload
.
hwsrc
mac
=
res
.
payload
.
hwsrc
arp_cache
[
ip
]
=
(
mac
,
time
.
time
())
conf
.
netcache
.
arp_cache
[
ip
]
=
mac
return
mac
return
mac
return
None
return
None
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment