Skip to content

Commit

Permalink
Fix arping() without routes configured (#4293)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed Feb 26, 2024
1 parent 1354e4b commit 4067950
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
24 changes: 19 additions & 5 deletions scapy/layers/l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,18 +1004,32 @@ def show(self, *args, **kwargs):
@conf.commands.register
def arping(net, timeout=2, cache=0, verbose=None, **kargs):
# type: (str, int, int, Optional[int], **Any) -> Tuple[ARPingResult, PacketList] # noqa: E501
"""Send ARP who-has requests to determine which hosts are up
arping(net, [cache=0,] [iface=conf.iface,] [verbose=conf.verb]) -> None
Set cache=True if you want arping to modify internal ARP-Cache"""
"""
Send ARP who-has requests to determine which hosts are up::
arping(net, [cache=0,] [iface=conf.iface,] [verbose=conf.verb]) -> None
Set cache=True if you want arping to modify internal ARP-Cache
"""
if verbose is None:
verbose = conf.verb

hwaddr = None
if "iface" in kargs:
hwaddr = get_if_hwaddr(kargs["iface"])
r = conf.route.route(str(net), verbose=False)

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

Expand Down
3 changes: 2 additions & 1 deletion scapy/sendrecv.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ def _sndrcv_snd(self):
self.hsent.setdefault(p.hashret(), []).append(p)
# Send packet
self.pks.send(p)
time.sleep(self.inter)
if self.inter:
time.sleep(self.inter)
i += 1
if self.verbose:
print("Finished sending %i packets." % i)
Expand Down

0 comments on commit 4067950

Please sign in to comment.