Skip to content

Commit a867caf

Browse files
committed
add geolocating ip addresses tutorial
1 parent ccdc302 commit a867caf

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
3939
- [How to Make a Password Generator in Python](https://www.thepythoncode.com/article/make-a-password-generator-in-python). ([code](ethical-hacking/password-generator))
4040
- [How to Make a Ransomware in Python](https://www.thepythoncode.com/article/make-a-ransomware-in-python). ([code](ethical-hacking/ransomware))
4141
- [How to Perform DNS Enumeration in Python](https://www.thepythoncode.com/article/dns-enumeration-with-python). ([code](ethical-hacking/dns-enumeration))
42+
- [How to Geolocate IP addresses in Python](https://www.thepythoncode.com/article/geolocate-ip-addresses-with-ipinfo-in-python). ([code](ethical-hacking/geolocating-ip-addresses))
4243

4344
- ### [Machine Learning](https://www.thepythoncode.com/topic/machine-learning)
4445
- ### [Natural Language Processing](https://www.thepythoncode.com/topic/nlp)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Geolocate IP addresses in Python](https://www.thepythoncode.com/article/geolocate-ip-addresses-with-ipinfo-in-python)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import ipinfo
2+
import sys
3+
# get the ip address from the command line
4+
try:
5+
ip_address = sys.argv[1]
6+
except IndexError:
7+
ip_address = None
8+
# access token for ipinfo.io
9+
access_token = '<put_your_access_token_here>'
10+
# create a client object with the access token
11+
handler = ipinfo.getHandler(access_token)
12+
# get the ip info
13+
details = handler.getDetails(ip_address)
14+
# print the ip info
15+
for key, value in details.all.items():
16+
print(f"{key}: {value}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ipinfo

0 commit comments

Comments
 (0)