Get RUS data

This commit is contained in:
Be
2024-03-02 22:54:08 +01:00
parent b12295874f
commit 2a2b8fbeab
7 changed files with 40 additions and 19346 deletions

View File

@@ -8,7 +8,7 @@ env:
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
- cron: '0 2 * * *'
jobs:
build:

View File

@@ -8,7 +8,7 @@ env:
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 0'
- cron: '0 1 * * 0'
jobs:
build:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,26 +1,49 @@
#!/usr/bin/env python3
import requests
import socket
url = "https://stat.ripe.net/data/country-resource-list/data.json?resource=RU&v4_format=prefix"
whois_server = "whois.ripe.net"
out_file_asn = "auto/all-ru-asn.txt"
out_file_ipv4 = "auto/all-ru-ipv4.txt"
out_file_ipv6 = "auto/all-ru-ipv6.txt"
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=""):
with open(file, 'w') as f:
for x in json['data']['resources'][attr]:
x = prefix+x.strip()
response = whois_query(whois_server, x, field)
name = response.split(':')[1].strip()
print(f"{x} {name}")
f.write(str(x+" "+name) + '\n')
response = requests.get(url)
response.raise_for_status()
data = response.json()
with open(out_file_asn, 'w') as f:
for asn in data['data']['resources']['asn']:
f.write(str("AS"+asn) + '\n')
with open(out_file_ipv4, 'w') as f:
for ipv4 in data['data']['resources']['ipv4']:
f.write(str(ipv4) + '\n')
with open(out_file_ipv6, 'w') as f:
for ipv6 in data['data']['resources']['ipv6']:
f.write(str(ipv6) + '\n')
get_data(data, 'auto/all-ru-asn.txt', 'asn', 'as-name', "AS")
get_data(data, 'auto/all-ru-ipv4.txt', 'ipv4', 'netname')
get_data(data, 'auto/all-ru-ipv6.txt', 'ipv6', 'netname')

View File

@@ -12,11 +12,9 @@ def whois_query(whois_server, query):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((whois_server, 43))
# Prepare the query
query = f"{query}\r\n"
s.send(query.encode())
# Collect the response
response = ''
while True:
data = s.recv(4096)
@@ -28,7 +26,6 @@ def whois_query(whois_server, query):
break
s.close()
# Extract the inetnum line
for line in response.split('\n'):
if line.startswith('inetnum'):
return line.strip()