File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ import socket
2
+ import socks
3
+ import dns .message # pip install dnspython
4
+
5
+ def create_dns_query (domain ):
6
+ # Create a DNS query message
7
+ query = dns .message .make_query (domain , 'A' )
8
+ return query .to_wire ()
9
+
10
+ def parse_dns_response (response_data ):
11
+ # Parse the DNS response
12
+ response = dns .message .from_wire (response_data )
13
+ return response
14
+
15
+ # Setup SOCKS connection
16
+ s = socks .socksocket (socket .AF_INET , socket .SOCK_DGRAM )
17
+ s .set_proxy (socks .SOCKS5 , "localhost" , 1337 ) # your SOCKS5 port
18
+
19
+ try :
20
+ # Send DNS query for google.com
21
+ query_data = create_dns_query ("google.com" )
22
+ s .sendto (query_data , ("8.8.8.8" , 53 )) # Google's DNS server
23
+
24
+ # Receive response
25
+ data , addr = s .recvfrom (1024 )
26
+
27
+ # Parse and print response
28
+ response = parse_dns_response (data )
29
+ print (f"Response from { addr } :" )
30
+ print (response )
31
+
32
+ # Print A records
33
+ for answer in response .answer :
34
+ for item in answer .items :
35
+ if item .rdtype == dns .rdatatype .A :
36
+ print (f"IP Address: { item } " )
37
+
38
+ except Exception as e :
39
+ print (f"Error: { e } " )
40
+ finally :
41
+ s .close ()
You can’t perform that action at this time.
0 commit comments