Last active
July 2, 2020 09:40
-
-
Save joaoceron/5b9f8574153a230fe23edf8422d23123 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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