-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathtest_udp.py
41 lines (33 loc) · 1.07 KB
/
test_udp.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
38
39
40
41
import socket
import socks
import dns.message # pip install dnspython
def create_dns_query(domain):
# Create a DNS query message
query = dns.message.make_query(domain, 'A')
return query.to_wire()
def parse_dns_response(response_data):
# Parse the DNS response
response = dns.message.from_wire(response_data)
return response
# Setup SOCKS connection
s = socks.socksocket(socket.AF_INET, socket.SOCK_DGRAM)
s.set_proxy(socks.SOCKS5, "localhost", 1337) # your SOCKS5 port
try:
# Send DNS query for google.com
query_data = create_dns_query("google.com")
s.sendto(query_data, ("8.8.8.8", 53)) # Google's DNS server
# Receive response
data, addr = s.recvfrom(1024)
# Parse and print response
response = parse_dns_response(data)
print(f"Response from {addr}:")
print(response)
# Print A records
for answer in response.answer:
for item in answer.items:
if item.rdtype == dns.rdatatype.A:
print(f"IP Address: {item}")
except Exception as e:
print(f"Error: {e}")
finally:
s.close()