0

I'm programing in python 2.7 and i have tried to write a function which asking for ip address from the DHCP server, the problem is that after I'm sending the packet and do sniffing for DHCP offer the sniffing doesn't catch it(i can see the offer on wireshark), I have no idea why, a friend of mine told me that maybe, since the net isn't so loaded the DHCP offer response is too fast(between the DHCP-descover and offer there's 0.000335059 sec, according wireshark) and the sniffing start working after the offer has arrived. so first, is it true? If this is true how can i fix it? here's the script

def get_ip_address(mac):
ethernet = Ether(dst='ff:ff:ff:ff:ff:ff', src=myMac, type=0x800)
ip = IP(src='0.0.0.0', dst='255.255.255.255')
udp = UDP(sport=68, dport=67)
bootp = BOOTP(chaddr=mac, ciaddr='0.0.0.0', xid=0x01020304, flags=1)
dhcp = DHCP(options=[("message-type", "discover"), "end"])

packet = ethernet / ip / udp / bootp / dhcp
**sendp(packet, iface=myInterface)**
**a= sniff(count=1, iface=myInterface,filter="(udp) and(port 67 or port 68)")**

dhcp1 = DHCP(options=[("message-type", "request"), ("server_id", a[BOOTP][0][3].siaddr),
                      ("requested_addr", a[BOOTP][0][3].yiaddr), "end"])
req_packet = ethernet / ip / udp / bootp / dhcp1
sendp(req_packet, iface=myInterface)
returned_ip = a[BOOTP][0][3].yiaddr
return returned_ip
  • " a friend of mine told me that . . . the net isn't so loaded the DHCP offer response is too fast. . . and the sniffing start working after the offer has arrived". I doubt that's the case. I've never run into that before, and it seems highly unlikely that sending something over the network would be faster than the execution of that line of code (even if it is a relatively expensive line). – Carcigenicate Jan 01 '21 at 15:14
  • This is a lot of very dense code (and it's meant for Python 3.5+), but [here](https://gist.github.com/carcigenicate/8ebb54a1db168e8d0e06525da896985b) is some code that I wrote awhile ago when I was attempting to write a malicious DHCP client, if you want to use it for reference. "attacker" in this case is your MAC, while the "client" is the MAC you're requesting a new address for. – Carcigenicate Jan 01 '21 at 15:32

0 Answers0