-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from dizda/chore/udp-python
chore: small python sscript to test dns query thru udp proxy
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() |