new code for ip checking

This commit is contained in:
lordvader501 2022-10-01 09:56:37 +05:30
parent ef664ebb59
commit 2233f1aa13
2 changed files with 8 additions and 12 deletions

View File

@ -1,10 +1,14 @@
# 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.
It is a python code to make a request to [https://ipv4.icanhazip.com](https://ipv4.icanhazip.com), 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.
#### Requirements:
* Install requests module.
* run `pip install requests`
#### Usage
* Clone the repo

View File

@ -1,13 +1,5 @@
from urllib.request import urlopen
from requests import get
url = "http://checkip.dyndns.org"
ip = get('https://ipv4.icanhazip.com').text
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)
print('>>> My public IP address is: ' + ip[0:-1] + ' <<<')