【问题标题】:Accessing Fields in scapy DHCP request访问 scapy DHCP 请求中的字段
【发布时间】:2020-10-07 14:07:34
【问题描述】:

我决定尝试使用 scapy 请求 IP。我能够在变量 ansD 中发送发现并接收报价。不幸的是,我无法访问包含提供的 IP 地址的字段,该地址应该是 ansD[BOOTP].yiaddr 。它告诉我该字段不存在。我环顾四周,看到了类似的问题,但似乎无法理解为什么我可以访问正常的数据包字段,但无法使用 BOOTP 字段。

receivedIP = 0
conf.checkIPaddr = False
fam,hw = get_if_raw_hwaddr(conf.iface)
dhcp_discover = Ether(dst="ff:ff:ff:ff:ff:ff")/IP(src="0.0.0.0",dst="255.255.255.255")/UDP(sport=68,dport=67)/BOOTP(chaddr=hw)/DHCP(options=[("message-type","discover"),"end"])
ansD,unans = srp(dhcp_discover, multi=True)

if True:
dhcp_request=Ether(dst="ff:ff:ff:ff:ff:ff")/IP(src="0.0.0.0",dst="255.255.255.255")/UDP(sport=68,dport=67)/BOOTP(chaddr=hw,yiaddr=ansD[BOOTP].yiaddr)/DHCP(options=[("message-type","request"),"end"])
ansR, unans = srp(dhcp_request,multi=True)

对象错误“列表”对象没有属性“yiaddr”

【问题讨论】:

    标签: python scapy dhcp bootp


    【解决方案1】:

    我在发布后不到两秒钟就知道了,但希望这对以后的其他人有所帮助。

    我使用 srp() 而不是 srp1(),前者返回多个数据包,所以我需要索引我想查看的特定数据包 ansD[0][BOOTP].yiaddr 。此后,我将代码更改为使用 srp1,因为这是一个 DHCP 请求,只期望 DHCP 服务器提供一个特定的“提议”回复。 下面的固定代码

    import sys
    from scapy.all import *
    
    
    receivedIP = 0
    conf.checkIPaddr = False
    fam,hw = get_if_raw_hwaddr(conf.iface)
    dhcp_discover=Ether(dst="ff:ff:ff:ff:ff:ff")/IP(src="0.0.0.0",dst="255.255.255.255")/UDP(sport=68,dport=67)/BOOTP(chaddr=hw)/DHCP(options=[("message-type","discover"),"end"])
    ansD = srp1(dhcp_discover, multi=True)
    if True:
    //Request using the IP the server offered us in ansD[BOOTP].yiaddr    
    
        dhcp_request = Ether(dst="ff:ff:ff:ff:ff:ff")/IP(src="0.0.0.0",dst="255.255.255.255")/UDP(sport=68,dport=67)/BOOTP(chaddr=hw,yiaddr=ansD[BOOTP].yiaddr)/DHCP(options=[("message-type","request"),"end"])
        ansR, unans = srp(dhcp_request,multi=True)
        ansR.summary()
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-25
      相关资源
      最近更新 更多