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:
@@ -2,34 +2,9 @@
|
||||
|
||||
import argparse
|
||||
import requests
|
||||
import socket
|
||||
from pylib.whois import whois_query
|
||||
|
||||
url = "https://stat.ripe.net/data/country-resource-list/data.json?resource=RU&v4_format=prefix"
|
||||
whois_server = "whois.ripe.net"
|
||||
|
||||
def whois_query(whois_server, query, get_field="netname"):
|
||||
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
|
||||
|
||||
def get_data(json, file, attr, field, prefix=""):
|
||||
limit = args.limit
|
||||
@@ -41,7 +16,7 @@ def get_data(json, file, attr, field, prefix=""):
|
||||
if count > limit:
|
||||
response = None
|
||||
else:
|
||||
response = whois_query(whois_server, x, field)
|
||||
response = whois_query(x, field)
|
||||
if response is None:
|
||||
name = "-no-description-"
|
||||
else:
|
||||
|
||||
@@ -1,36 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import socket
|
||||
import argparse
|
||||
import requests
|
||||
import ipaddress
|
||||
import re
|
||||
|
||||
whois_server = "whois.ripe.net"
|
||||
|
||||
def whois_query(whois_server, query, get_field="netname"):
|
||||
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
|
||||
from pylib.whois import whois_query
|
||||
|
||||
def convert_to_raw_github_url(url):
|
||||
return url.replace("https://github.com/", "https://raw.githubusercontent.com/").replace("/blob", "")
|
||||
@@ -55,7 +29,7 @@ def extract_netname(filename_or_url):
|
||||
for line in lines:
|
||||
if re.match(r'^netname:', line):
|
||||
netname = line.split(':')[1].strip()
|
||||
response = whois_query(whois_server, netname, "inetnum")
|
||||
response = whois_query(netname, "inetnum")
|
||||
if response is not None:
|
||||
if not args.quiet:
|
||||
print(f"# Network name: {netname}")
|
||||
|
||||
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