mirror of
https://github.com/C24Be/AS_Network_List.git
synced 2026-01-24 23:26:38 +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:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * *'
|
- cron: '0 2 * * *'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
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:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * 0'
|
- cron: '0 1 * * 0'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
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
|
#!/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')
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user