mirror of
https://github.com/C24Be/AS_Network_List.git
synced 2026-01-25 07:26:59 +03:00
whois
This commit is contained in:
BIN
pylib/__pycache__/whois.cpython-311.pyc
Normal file
BIN
pylib/__pycache__/whois.cpython-311.pyc
Normal file
Binary file not shown.
28
pylib/whois.py
Executable file
28
pylib/whois.py
Executable file
@@ -0,0 +1,28 @@
|
||||
import socket
|
||||
|
||||
def whois_query(query, get_field="netname"):
|
||||
|
||||
whois_server = "whois.ripe.net"
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((whois_server, 43))
|
||||
|
||||
query = f"{query}\r\n"
|
||||
s.send(query.encode())
|
||||
|
||||
response = ''
|
||||
while True:
|
||||
data = s.recv(4096)
|
||||
try:
|
||||
response += data.decode('utf-8')
|
||||
except:
|
||||
response += data.decode('latin-1')
|
||||
if not data:
|
||||
break
|
||||
s.close()
|
||||
|
||||
for line in response.split('\n'):
|
||||
if line.startswith(get_field + ':'):
|
||||
return line.strip()
|
||||
|
||||
return None
|
||||
Reference in New Issue
Block a user