mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
new code for ip checking
This commit is contained in:
parent
ef664ebb59
commit
2233f1aa13
|
@ -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
|
||||
|
|
|
@ -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] + ' <<<')
|
Loading…
Reference in New Issue
Block a user