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