-
Notifications
You must be signed in to change notification settings - Fork 2
/
dns-info
39 lines (30 loc) · 1.01 KB
/
dns-info
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
#!/usr/bin/env python3
import socket, sys
def query_whois_server(domain, server, port=43):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((server, port))
s.send((domain + "\r\n").encode())
data = s.recv(4096)
s.close()
return data.decode('utf-8', errors='ignore')
except Exception as e:
print(f"Error querying {server}: {e}")
return None
response_iana = query_whois_server(sys.argv[1], "whois.iana.org")
if not response_iana:
sys.exit(1)
response_lines = response_iana.split("\n")
whois_server = None
for line in response_lines:
if "whois:" in line.lower():
whois_server = line.split(":")[1].strip()
break
if not whois_server:
print("Unable to find the responsible WHOIS server.")
sys.exit(1)
response_final = query_whois_server(sys.argv[1], whois_server)
if response_final:
print(response_final)
else:
print(f"Unable to retrieve information for {sys.argv[1]} using server {whois_server}.")