Skip to content

Instantly share code, notes, and snippets.

@jjsantanna
Created February 12, 2020 10:12
Show Gist options
  • Save jjsantanna/c1083e5d323292dd55dab80bd861bfbf to your computer and use it in GitHub Desktop.
Save jjsantanna/c1083e5d323292dd55dab80bd861bfbf to your computer and use it in GitHub Desktop.
ip2location paid
#by João Ceron
import IP2Location
def ip2location_geo(pandaseries_ips):
ip2location = IP2Location.IP2Location()
ip2locationdb="IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ISP.BIN"
ip2location.open(ip2locationdb)
# country
df = pd.DataFrame(columns=['ip','cc'])
rows_list = []
unique_ip = pandaseries_ips.unique()
for ip in (unique_ip):
cc = ip2location.get_country_short(ip).decode("utf-8").replace("'","")
lat = ip2location.get_latitude(ip)
long = ip2location.get_longitude(ip)
row = {"ip": ip,
"cc": cc,
"lat": lat,
"long":long,
}
rows_list.append(row)
df = pd.DataFrame(rows_list)
print (len(df))
return (df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment