Merge pull request #28 from lordvader501/ip-checker

new code for ip checking
This commit is contained in:
Advaita Saha 2022-10-01 11:26:43 +05:30 committed by GitHub
commit bbe27a15d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View File

@ -1,10 +1,14 @@
# Public IP Address # Public IP Address
### Find your external IP address on the internet ### 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. 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 #### Usage
* Clone the repo * 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 + "...") print('>>> My public IP address is: ' + ip[0:-1] + ' <<<')
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)