Search code examples
pythondnsscapy

Why am i getting this error when i try to answer my own dns request?


import scapy.all as scapy
p = scapy.DNS(qd=scapy.DNSQR(qname='www.example.com'), an=scapy.DNSRR(rrname='127.0.0.1'))
scapy.send(p)

result :

    Traceback (most recent call last):
  File "/home/kali/PROJECTS/server.py", line 3, in <module>
    scapy.send(p)
  File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 425, in send
    return _send(
  File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 395, in _send
    results = __gen_send(socket, x, inter=inter, loop=loop,
  File "/usr/lib/python3/dist-packages/scapy/sendrecv.py", line 360, in __gen_send
    s.send(p)
  File "/usr/lib/python3/dist-packages/scapy/arch/linux.py", line 605, in send
    self.outs.bind(sdto)
TypeError: AF_PACKET address must be a tuple of two to five elements

Why am i getting this error when i try to answer my own dns request ?


Solution

  • You have to specify the destination address and the ports.

    p = scapy.IP(dst='127.0.0.1') / scapy.UDP(sport=53, dport = client_port) / scapy.DNS(qd=scapy.DNSQR(qname='www.example.com'), an=scapy.DNSRR(rrname='127.0.0.1'))