Skip to content

Commit

Permalink
Update pia_subnet_csv.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sudesh0sudesh authored Nov 13, 2024
1 parent 02eb4e1 commit f571a6a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pia_subnet_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def fetch_asn(subnet):
try:
response = requests.get(f"{IP_GUIDE_URL}{subnet}")
if response.status_code == 200:
data = response.json().get('autonomous_system', {})
data = response.json().get('network', {}).get('autonomous_system', {})
elif response.status_code == 404:
ip = subnet.split('/')[0]
response = requests.get(f"{IP_GUIDE_URL}{ip}")
Expand Down Expand Up @@ -63,10 +63,11 @@ def main():

output = []
for subnet in subnets:
asn, asn_org, country, first_seen, last_seen = fetch_asn(subnet+"/32")
asn, asn_org, country, first_seen, last_seen = fetch_asn(subnet)
if asn:
output.append([subnet, asn, asn_org, country, first_seen, last_seen])


output = list(set(output))
old_output = read_csv(OUTPUT_FILE)

if not old_output:
Expand Down

0 comments on commit f571a6a

Please sign in to comment.