From b54f7f6d3b7040b256e87383966dce4ce9e4441b Mon Sep 17 00:00:00 2001 From: bartick Date: Fri, 16 Sep 2022 23:29:42 +0530 Subject: [PATCH] add: Get your public ip --- scripts/Public_IP_Address/README.md | 13 +++++++++++++ scripts/Public_IP_Address/my_public_ip.py | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 scripts/Public_IP_Address/README.md create mode 100644 scripts/Public_IP_Address/my_public_ip.py diff --git a/scripts/Public_IP_Address/README.md b/scripts/Public_IP_Address/README.md new file mode 100644 index 0000000..fc7f474 --- /dev/null +++ b/scripts/Public_IP_Address/README.md @@ -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. diff --git a/scripts/Public_IP_Address/my_public_ip.py b/scripts/Public_IP_Address/my_public_ip.py new file mode 100644 index 0000000..97d10ea --- /dev/null +++ b/scripts/Public_IP_Address/my_public_ip.py @@ -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) \ No newline at end of file