-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
37 lines (24 loc) · 844 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import socket
from scapy.all import *
from dns import DNSParser, format_dns, QuestionRecord
def main():
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
# sock.bind(('127.0.0.1', 0))
addr = '8.8.8.8'
iface_name, iface_addr, gateway = conf.route.route(addr)
print(f"Sending via {iface_name}")
sock.bind((iface_addr, 0))
questions = [
QuestionRecord("nus.edu.sg", 0x0002, 1)
]
dns_send = format_dns(questions=questions)
sock.sendto(dns_send, (addr, 53))
data, addr = sock.recvfrom(512)
packet = DNSParser(data).parse()
print(packet["qnlen"])
print(packet["anlen"])
return
for record in packet['sections']['ad']:
print(record)
if __name__ == "__main__":
main()