Skip to content

Instantly share code, notes, and snippets.

@lero
Created September 9, 2019 10:39
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 lero/bf7659214a6fc0c7bb238c935a17bd83 to your computer and use it in GitHub Desktop.
Save lero/bf7659214a6fc0c7bb238c935a17bd83 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from scapy.all import *
conf.checkIPaddr=False
# configuration
localiface = 'eno1'
requestMAC = 'ac:16:2d:ab:14:98'
myhostname = '\0'
localmac = get_if_hwaddr(localiface)
localmacraw = requestMAC.replace(':','').decode('hex')
# craft DHCP DISCOVER
dhcp_discover = Ether(src=localmac, dst='ff:ff:ff:ff:ff:ff')/IP(src='0.0.0.0', dst='255.255.255.255')/UDP(dport=67, sport=68)/BOOTP(chaddr=localmacraw,xid=RandInt())/DHCP(options=[('message-type', 'discover'),('hostname', myhostname), 'end'])
print dhcp_discover.display()
# send discover, wait for reply
dhcp_offer = srp1(dhcp_discover,iface=localiface)
print dhcp_offer.display()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment