mirror of
https://github.com/C24Be/AS_Network_List.git
synced 2026-01-25 15:31:12 +03:00
Get RUS data
This commit is contained in:
2
.github/workflows/update_blacklists.yml
vendored
2
.github/workflows/update_blacklists.yml
vendored
@@ -8,7 +8,7 @@ env:
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
- cron: '0 2 * * *'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
2
.github/workflows/update_ru_all_lists.yml
vendored
2
.github/workflows/update_ru_all_lists.yml
vendored
@@ -8,7 +8,7 @@ env:
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 0 * * 0'
|
||||
- cron: '0 1 * * 0'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
5806
auto/all-ru-asn.txt
5806
auto/all-ru-asn.txt
File diff suppressed because it is too large
Load Diff
11087
auto/all-ru-ipv4.txt
11087
auto/all-ru-ipv4.txt
File diff suppressed because it is too large
Load Diff
2433
auto/all-ru-ipv6.txt
2433
auto/all-ru-ipv6.txt
File diff suppressed because it is too large
Load Diff
@@ -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"
|
||||
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')
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user