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

Question:

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 ?

Asked By: Essence

||

Answers:

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'))
Answered By: Barmar
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.