add: Get your public ip

This commit is contained in:
bartick 2022-09-16 23:29:42 +05:30
parent 8d41da5c7f
commit b54f7f6d3b
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# Public IP Address
### Find your external IP address on the internet
It is a python code to make a request to [http://checkip.dyndns.org](http://checkip.dyndns.org), which in turn send a response back with your External IP address.
This response is in HTML so it also extracts only useful information from it and prints it as an output.
#### Usage
* Clone the repo
* open the `Public IP Address` folder
* run `python my_public_ip.py`
* You just recieved your public IP.

View File

@ -0,0 +1,13 @@
from urllib.request import urlopen
url = "http://checkip.dyndns.org"
print("Making request to " + url + "...")
request = urlopen(url)
print("Reading the response...")
response = request.read()
print("Extracting your IP info...")
ip = ">>> " + response.decode("utf-8").split("body")[1][1:-2] + " <<<"
print(ip)