2022-04-11 19:28:20 +02:00
|
|
|
import time
|
|
|
|
import requests
|
|
|
|
from settings import (get_connection, key)
|
|
|
|
|
|
|
|
def process_queries(sql_statement):
|
|
|
|
with get_connection() as conn:
|
|
|
|
with conn.cursor() as cur:
|
|
|
|
cur.execute(sql_statement)
|
|
|
|
res = cur.fetchall()
|
2022-04-09 21:49:47 +02:00
|
|
|
for index, r in enumerate(res):
|
|
|
|
steam_id = r[0]
|
|
|
|
ip = r[1]
|
2022-04-09 21:52:08 +02:00
|
|
|
url = f"https://proxycheck.io/v2/{ip}?key={key}&asn=1"
|
2022-04-09 21:49:47 +02:00
|
|
|
jrequest = requests.get(url).json()
|
|
|
|
d = jrequest[ip]
|
2022-04-11 19:28:20 +02:00
|
|
|
try:
|
2022-04-10 16:01:19 +02:00
|
|
|
asn = d["asn"]
|
|
|
|
provider = d["provider"]
|
|
|
|
country = d["country"]
|
|
|
|
except Exception:
|
|
|
|
print(f'failed: {jrequest}')
|
|
|
|
continue
|
2022-04-09 21:49:47 +02:00
|
|
|
with get_connection() as conn:
|
|
|
|
with conn.cursor() as cur:
|
|
|
|
sql_statement = """
|
|
|
|
insert ignore into `unloze_anti-spoofing`.connect_restriction
|
|
|
|
(country, asn, provider, steam_id, ipv4)
|
|
|
|
values (%s, %s, %s, %s, %s)
|
|
|
|
"""
|
|
|
|
cur.execute(sql_statement, [country, asn, provider, steam_id, ip])
|
|
|
|
conn.commit()
|
2022-04-11 19:28:20 +02:00
|
|
|
time.sleep(2.5)
|
|
|
|
print(f'at {index + 1}/{len(res)}')
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
sql_statement = """
|
|
|
|
select sb.steam_id, sb.ipv4
|
|
|
|
from `unloze_anti-spoofing`.sb_bans_shortened sb
|
|
|
|
left outer join `unloze_anti-spoofing`.connect_restriction cr on
|
|
|
|
sb.steam_id = cr.steam_id
|
|
|
|
where cr.asn is null
|
|
|
|
limit 40
|
|
|
|
"""
|
|
|
|
process_queries(sql_statement)
|
|
|
|
sql_statement = """
|
|
|
|
select auth, address
|
|
|
|
from `unloze_anti-spoofing`.connections sb
|
|
|
|
left join `unloze_anti-spoofing`.connect_restriction cr on
|
|
|
|
sb.auth = cr.steam_id and sb.address = cr.ipv4
|
|
|
|
where cr.asn is null
|
|
|
|
and sb.type != 'SteamLegit'
|
|
|
|
limit 950
|
|
|
|
"""
|
|
|
|
process_queries(sql_statement)
|
2022-04-09 21:49:47 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|