1 from scapy.all import *
2 from scapy.layers import *
6 server_mac="00:0B:CD:AE:9F:C6"
7 client_mac="aa:a2:a5:ea:54:20"
8 subnet_mask="255.255.255.0"
11 # suboption 1 Agent circuit ID; len:4; val:0x00000001
12 # suboption 5 Link selection; len:4; val:6.0.1.1
13 option82 = '\x01\x04\x00\x00\x00\x01\x05\x04\x06\00\x01\x01'
16 # check if we get DHCP discover and send offer message
17 if pkt[DHCP] and pkt[DHCP].options[0][1] == 1:
18 sendp(Ether(src=server_mac,dst="ff:ff:ff:ff:ff:ff")/
19 IP(src=server_ip,dst="6.0.1.1")/
20 UDP(sport=67,dport=68)/
21 BOOTP(op=2, yiaddr=client_ip, siaddr=server_ip, giaddr=gateway,
22 chaddr=client_mac, xid=pkt[BOOTP].xid)/
23 DHCP(options=[('message_type', 'offer')])/
24 DHCP(options=[('subnet_mask',subnet_mask)])/
25 DHCP(options=[('server_id',server_ip)])/
26 DHCP(options=[('relay_agent_Information', option82), ('end')]))
30 sniff(filter="udp and (port 67 or 68)", prn=detect_dhcp, store=0)