Skip to content

Instantly share code, notes, and snippets.

@joaoceron
Last active July 2, 2020 09:40
Show Gist options
  • Save joaoceron/5b9f8574153a230fe23edf8422d23123 to your computer and use it in GitHub Desktop.
Save joaoceron/5b9f8574153a230fe23edf8422d23123 to your computer and use it in GitHub Desktop.
# https://github.com/hadiasghari/pyasn
# pyasn_util_download.py --latest
# pyasn_util_convert.py --single <Downloaded RIB File> <ipasn_db_file_name>
# load database
asndb = pyasn.pyasn('ipasn.dat')
# convert one ip to asn
def pyasn(ip,asndb):
asn, prefix = asndb.lookup(ip)
dic = {
"ip": ip,
"asn": asn,
}
return (dic)
# MAIN
array_df = []
for ip in df.ip.unique().tolist():
if (ip=="0"): # do it better, you can :)
continue
array_df.append(pyasn(ip, asndb))
df_asn = pd.DataFrame(array_df)
df_asn.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment