Skip to content

Instantly share code, notes, and snippets.

@whoo
Last active April 7, 2023 15:46
Show Gist options
  • Save whoo/67277854615ab8c46d8fa5b198ad95ac to your computer and use it in GitHub Desktop.
Save whoo/67277854615ab8c46d8fa5b198ad95ac to your computer and use it in GitHub Desktop.
put ip on a map
import plotly.express as px
import pandas as pd
import geoip2.database
## https://www.maxmind.com/en/accounts/595343/geoip/downloads
reader=geoip2.database.Reader('GeoLite2-City.mmdb')
ip=["x.x.x.x" ,
"x.x.x.x" ,
"x.x.x.x"
]
d=[]
for _ in ip:
d.append({
'city': reader.city(_).city.names['en'],
'lat': reader.city(_).location.latitude,
'lon': reader.city(_).location.longitude})
p=pd.DataFrame(d)
fig = px.scatter_mapbox(d, lat='lat',lon='lon',hover_name='city', color_discrete_sequence=["fuchsia"])
fig.update_layout(mapbox_style="open-street-map")
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment