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
+1 -1
View File
@@ -8,7 +8,7 @@ env:
on: on:
workflow_dispatch: workflow_dispatch:
schedule: schedule:
- cron: '0 0 * * *' - cron: '0 2 * * *'
jobs: jobs:
build: build:
+1 -1
View File
@@ -8,7 +8,7 @@ env:
on: on:
workflow_dispatch: workflow_dispatch:
schedule: schedule:
- cron: '0 0 * * 0' - cron: '0 1 * * 0'
jobs: jobs:
build: build:
-5806
View File
File diff suppressed because it is too large Load Diff
-11087
View File
File diff suppressed because it is too large Load Diff
-2433
View File
File diff suppressed because it is too large Load Diff
+37 -14
View File
@@ -1,26 +1,49 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import requests import requests
import socket
url = "https://stat.ripe.net/data/country-resource-list/data.json?resource=RU&v4_format=prefix" 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" def whois_query(whois_server, query, get_field="netname"):
out_file_ipv4 = "auto/all-ru-ipv4.txt" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
out_file_ipv6 = "auto/all-ru-ipv6.txt" 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 = requests.get(url)
response.raise_for_status() response.raise_for_status()
data = response.json() data = response.json()
with open(out_file_asn, 'w') as f: get_data(data, 'auto/all-ru-asn.txt', 'asn', 'as-name', "AS")
for asn in data['data']['resources']['asn']: get_data(data, 'auto/all-ru-ipv4.txt', 'ipv4', 'netname')
f.write(str("AS"+asn) + '\n') get_data(data, 'auto/all-ru-ipv6.txt', 'ipv6', 'netname')
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')
-3
View File
@@ -12,11 +12,9 @@ def whois_query(whois_server, query):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((whois_server, 43)) s.connect((whois_server, 43))
# Prepare the query
query = f"{query}\r\n" query = f"{query}\r\n"
s.send(query.encode()) s.send(query.encode())
# Collect the response
response = '' response = ''
while True: while True:
data = s.recv(4096) data = s.recv(4096)
@@ -28,7 +26,6 @@ def whois_query(whois_server, query):
break break
s.close() s.close()
# Extract the inetnum line
for line in response.split('\n'): for line in response.split('\n'):
if line.startswith('inetnum'): if line.startswith('inetnum'):
return line.strip() return line.strip()