带有自定义选项的scapy dhcp请求

时间:2017-01-09 21:52:20

标签: python scapy dhcp

如何利用scapy作为dhcp客户端请求某些DHCP选项?客户端将请求他们需要的内容,并且dhcp客户端应该相应地做出响应。但是,我需要测试是否从服务器发送了某些DHCP选项,这些是我的PC通常不会请求的选项。这些可以是选项150,242等。

scapy可以支持任何DHCP选项吗?在下面的代码中,如果我想要请求选项242或选项150,我将如何调整?

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

packet = ethernet / ip / udp / bootp / dhcp

1 个答案:

答案 0 :(得分:0)

requested_option_1 = 1    # Subnet Mask
requested_option_2 = 6    # Domain Name Servers
requested_option_3 = 15   # Domain Name
requested_option_4 = 44   # NetBIOS (TCP/IP) Name Servers
requested_option_5 = 3    # Routers
requested_option_6 = 33   # Static Routes
requested_option_7 = 150  # TFTP Server address
requested_option_8 = 43   # Vendor Specific Information

bytes_requested_options = struct.pack("8B", requested_option_1,
                                            requested_option_2,
                                            requested_option_3,
                                            requested_option_4,
                                            requested_option_5,
                                            requested_option_6,
                                            requested_option_7,
                                            requested_option_8)
dhcp = DHCP(options=[('message-type', 'discover'),('param_req_list',bytes_requested_options),'end'])