Skip to content

Instantly share code, notes, and snippets.

@BlueSkyDetector
Created April 10, 2011 13:40
Show Gist options
  • Save BlueSkyDetector/912351 to your computer and use it in GitHub Desktop.
Save BlueSkyDetector/912351 to your computer and use it in GitHub Desktop.
detect number of DHCP server
#!/bin/env python
from scapy.all import *
conf.checkIPaddr = False
fam,hw = get_if_raw_hwaddr(conf.iface)
dhcp_discover = Ether(dst="ff:ff:ff:ff:ff:ff")/IP(src="0.0.0.0",dst="255.255.255.255")/UDP(sport=68,dport=67)/BOOTP(chaddr=hw)/DHCP(options=[("message-type","discover"),"end"])
ans, unans = srp(dhcp_discover, iface='eth0', multi=True, timeout=2, verbose=0)
print len(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment