Ghofrane
Ghofrane

Reputation: 1

DHCP offer packet

I get a DHCP discover from a client and I want to respond with a DHCP offer, but first I need to use the same transaction id from the DHCP discover.

I want to fetch the same id in DHCP discover so I have to sniff the DHCP discover packet and fetch that xid to use it but I don't know how.

The client sends discoveries successively and therefore I want to sniff the last packet received on the interface.

I tried some codes but I didn't get the result that I want. This my code:

packets=sniff(filter="udp and (port 67 or port 68)" ,iface="eth1")

for packet in packets :
  xid_dhcp=((packet[BOOTP].xid))
  print((packet[BOOTP].xid))

Upvotes: 0

Views: 125

Answers (1)

hase1010
hase1010

Reputation: 65

Your code is almost correct. However, since you only want to get the last packet received on the interface, you should get the last element of the packets list

last_packet = packets[-1]
xid_dhcp = last_packet[BOOTP].xid
print(xid_dhcp)

Hope this helps :)

Upvotes: 0

Related Questions