Skip to content

Instantly share code, notes, and snippets.

@vanhoefm
Last active June 21, 2020 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanhoefm/eb515eb8b0adac02081e07878f4f99b7 to your computer and use it in GitHub Desktop.
Save vanhoefm/eb515eb8b0adac02081e07878f4f99b7 to your computer and use it in GitHub Desktop.
Wait until the router booted
#!/usr/bin/env python3
from scapy.all import *
# MAC address of our own interface
MYMACADDR = "11:22:33:44:55:66"
def wait_router(iface, ip):
s = L2Socket(type=ETH_P_ALL, iface=iface)
arp = Ether(dst="ff:ff:ff:ff:ff:ff", src=MYMACADDR)
arp = arp/ARP(hwsrc=MYMACADDR, pdst=ip, psrc="192.168.0.100")
while True:
# Keep sending ARP requests for the IP of the router
print("Injecting")
s.send(arp)
p = list(sniff(opened_socket=s, count=1, timeout=0.1, \
lfilter=lambda p: ARP in p and p.psrc == ip))
if len(p) > 0:
break
# Wait until the router has booted
wait_router("enp3s0", "192.168.0.1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment