Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions scapy/layers/l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
from scapy.data import ARPHDR_ETHER, ARPHDR_LOOPBACK, ARPHDR_METRICOM, \
DLT_ETHERNET_MPACKET, DLT_LINUX_IRDA, DLT_LINUX_SLL, DLT_LINUX_SLL2, \
DLT_LOOP, DLT_NULL, ETHER_ANY, ETHER_BROADCAST, ETHER_TYPES, ETH_P_ARP, ETH_P_MACSEC
from scapy.error import warning, ScapyNoDstMacException, log_runtime
from scapy.error import (
ScapyNoDstMacException,
log_runtime,
warning,
)
from scapy.fields import (
BCDFloatField,
BitField,
Expand Down Expand Up @@ -938,7 +942,7 @@ def _tups(ip, mac):
# ip can be a Net/list/etc and will be iterated upon while sending
return [(ip, "ff:ff:ff:ff:ff:ff")]
return [(x.query.pdst, x.answer.hwsrc)
for x in arping(ip, verbose=0)[0]]
for x in arping(ip, verbose=0, iface=iface)[0]]
elif isinstance(mac, list):
return [(ip, x) for x in mac]
else:
Expand All @@ -960,6 +964,7 @@ def _tups(ip, mac):
(x
for ipa, maca in tup1
for ipb, _ in tup2
if ipb != ipa
for x in
Ether(dst=maca, src=target_mac) /
ARP(op="who-has", psrc=ipb, pdst=ipa,
Expand All @@ -968,6 +973,7 @@ def _tups(ip, mac):
(x
for ipb, macb in tup2
for ipa, _ in tup1
if ipb != ipa
for x in
Ether(dst=macb, src=target_mac) /
ARP(op="who-has", psrc=ipa, pdst=ipb,
Expand All @@ -987,6 +993,7 @@ def _tups(ip, mac):
(x
for ipa, maca in tup1
for ipb, macb in tup2
if ipb != ipa
for x in
Ether(dst="ff:ff:ff:ff:ff:ff", src=macb) /
ARP(op="who-has", psrc=ipb, pdst=ipa,
Expand All @@ -995,6 +1002,7 @@ def _tups(ip, mac):
(x
for ipb, macb in tup2
for ipa, maca in tup1
if ipb != ipa
for x in
Ether(dst="ff:ff:ff:ff:ff:ff", src=maca) /
ARP(op="who-has", psrc=ipa, pdst=ipb,
Expand Down Expand Up @@ -1055,19 +1063,33 @@ def arping(net: str,
hwaddr = None
if "iface" in kargs:
hwaddr = get_if_hwaddr(kargs["iface"])
r = conf.route.route(str(net), verbose=False)
if isinstance(net, list):
hint = net[0]
else:
hint = str(net)
psrc = conf.route.route(hint, verbose=False)[1]
if psrc == "0.0.0.0":
if "iface" in kargs:
psrc = get_if_addr(kargs["iface"])
else:
warning(
"No route found for IPv4 destination %s. "
"Using conf.iface. Please provide an 'iface' !" % hint)
psrc = get_if_addr(conf.iface)
hwaddr = get_if_hwaddr(conf.iface)
kargs["iface"] = conf.iface

ans, unans = srp(
Ether(dst="ff:ff:ff:ff:ff:ff", src=hwaddr) / ARP(
pdst=net,
psrc=r[1],
psrc=psrc,
hwsrc=hwaddr
),
verbose=verbose,
filter="arp and arp[7] = 2",
timeout=timeout,
threaded=threaded,
iface_hint=net,
iface_hint=hint,
**kargs,
)
ans = ARPingResult(ans.res)
Expand Down