From 5fa5e78a2cf4e361aab1b96742666bbdd8440de2 Mon Sep 17 00:00:00 2001 From: Yashesvinee V <76458668+Yashesvinee@users.noreply.github.com> Date: Tue, 5 Apr 2022 22:27:59 +0530 Subject: [PATCH 1/6] Add files via upload --- Python/IP-Hostname_Validator/README.md.txt | 1 + Python/IP-Hostname_Validator/main.py | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Python/IP-Hostname_Validator/README.md.txt create mode 100644 Python/IP-Hostname_Validator/main.py diff --git a/Python/IP-Hostname_Validator/README.md.txt b/Python/IP-Hostname_Validator/README.md.txt new file mode 100644 index 000000000..45b830f2a --- /dev/null +++ b/Python/IP-Hostname_Validator/README.md.txt @@ -0,0 +1 @@ +# IP Address and Hostname validator \ No newline at end of file diff --git a/Python/IP-Hostname_Validator/main.py b/Python/IP-Hostname_Validator/main.py new file mode 100644 index 000000000..797b1bd9f --- /dev/null +++ b/Python/IP-Hostname_Validator/main.py @@ -0,0 +1,24 @@ +import os, ipaddress, socket, sys + +if sys.argv[1]=="ip": + ip = sys.argv[2] + try: + print(ipaddress.ip_address(ip)) + print('IP Valid') + host = socket.gethostbyaddr(ip) + print("Host: " + str(host[0])) + except: + print('-' *25) + print('IP is not valid') + +elif sys.argv[1]=="hostname": + host = sys.argv[2] + try: + print(host) + ip = socket.gethostbyname(host) + print("IP Address: ", ip) + except: + print('-' *25) + print("Hostname does not exist") + + From fce48302729473d8402bb02ae68fd35c9e65ee12 Mon Sep 17 00:00:00 2001 From: Yashesvinee V <76458668+Yashesvinee@users.noreply.github.com> Date: Wed, 6 Apr 2022 20:55:37 +0530 Subject: [PATCH 2/6] Update and rename README.md.txt to README.md --- Python/IP-Hostname_Validator/README.md | 29 ++++++++++++++++++++++ Python/IP-Hostname_Validator/README.md.txt | 1 - 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 Python/IP-Hostname_Validator/README.md delete mode 100644 Python/IP-Hostname_Validator/README.md.txt diff --git a/Python/IP-Hostname_Validator/README.md b/Python/IP-Hostname_Validator/README.md new file mode 100644 index 000000000..b53f101c9 --- /dev/null +++ b/Python/IP-Hostname_Validator/README.md @@ -0,0 +1,29 @@ +# IP/Hostname Validator +### Libraries used: +- ipaddress - Provides functions to create, manipulate and operate in IPv4 and IPv6 addresses and networks. +- sys - Used to provide access to variables maintained by the interpreter. +- socket - Provides functions and objects to build network applications for clients and servers. It helps access the BSD Socket interface. + +### Description +The script can be used to find the: +- IP Address from hostname +- Hostname from an IP Address + +It mainly validates a given IP Address and Hostname. The IP Addresses are accepted in IPv4 and IPv6 formats. + +### Setup instructions +Navigate to Rotten-Scripts/Python/IP-Hostname_Validator. +To validate a given IP Address and get the hostname. +` +python main.py ip 8.8.8.8 +` +Output: +![image](https://user-images.githubusercontent.com/76458668/162009872-de378e0d-dc39-4894-bc6d-d9c98e538964.png) + + +To find the IP Address of a given hostname. +` +python main.py hostname facebook.com +` +Output: +![image](https://user-images.githubusercontent.com/76458668/162010700-d61a24b9-46bb-44c8-8e24-77f0e2c2baa9.png) diff --git a/Python/IP-Hostname_Validator/README.md.txt b/Python/IP-Hostname_Validator/README.md.txt deleted file mode 100644 index 45b830f2a..000000000 --- a/Python/IP-Hostname_Validator/README.md.txt +++ /dev/null @@ -1 +0,0 @@ -# IP Address and Hostname validator \ No newline at end of file From f72837ff8fe0d487f160c44fba23a07e6f6465b5 Mon Sep 17 00:00:00 2001 From: Yashesvinee V <76458668+Yashesvinee@users.noreply.github.com> Date: Wed, 6 Apr 2022 21:52:05 +0530 Subject: [PATCH 3/6] Update README.md --- Python/IP-Hostname_Validator/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Python/IP-Hostname_Validator/README.md b/Python/IP-Hostname_Validator/README.md index b53f101c9..6857ddb03 100644 --- a/Python/IP-Hostname_Validator/README.md +++ b/Python/IP-Hostname_Validator/README.md @@ -13,17 +13,27 @@ It mainly validates a given IP Address and Hostname. The IP Addresses are accept ### Setup instructions Navigate to Rotten-Scripts/Python/IP-Hostname_Validator. + To validate a given IP Address and get the hostname. + ` python main.py ip 8.8.8.8 ` + Output: + ![image](https://user-images.githubusercontent.com/76458668/162009872-de378e0d-dc39-4894-bc6d-d9c98e538964.png) To find the IP Address of a given hostname. + ` python main.py hostname facebook.com ` + Output: + ![image](https://user-images.githubusercontent.com/76458668/162010700-d61a24b9-46bb-44c8-8e24-77f0e2c2baa9.png) + +### Author +[Yashesvinee](https://github.com/Yashesvinee) From 8c2b699fd7fafa2b74da5973219ddae43b0b956b Mon Sep 17 00:00:00 2001 From: Yashesvinee V <76458668+Yashesvinee@users.noreply.github.com> Date: Wed, 6 Apr 2022 21:57:39 +0530 Subject: [PATCH 4/6] Update README.md --- Python/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/README.md b/Python/README.md index 27f88eb5b..af3a1c906 100644 --- a/Python/README.md +++ b/Python/README.md @@ -205,3 +205,4 @@ - [Zoom Automation](./Zipper) - [Linkedin Wish Sender](./Linkedin_Wishes_Sender) - [Facebook Friend Request Accepter](./Fb_Request_Accepter) +- [IP Address/Hostname Validator](./IP-Hostname_Validator) From 34f9ced0d07064af1489bd685fc831526fd034b8 Mon Sep 17 00:00:00 2001 From: Yashesvinee V <76458668+Yashesvinee@users.noreply.github.com> Date: Wed, 6 Apr 2022 22:17:07 +0530 Subject: [PATCH 5/6] Update main.py --- Python/IP-Hostname_Validator/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Python/IP-Hostname_Validator/main.py b/Python/IP-Hostname_Validator/main.py index 797b1bd9f..5e7b49e7c 100644 --- a/Python/IP-Hostname_Validator/main.py +++ b/Python/IP-Hostname_Validator/main.py @@ -1,4 +1,6 @@ -import os, ipaddress, socket, sys +import ipaddress +import socket +import sys if sys.argv[1]=="ip": ip = sys.argv[2] @@ -7,7 +9,7 @@ print('IP Valid') host = socket.gethostbyaddr(ip) print("Host: " + str(host[0])) - except: + except ValueError: print('-' *25) print('IP is not valid') @@ -15,9 +17,10 @@ host = sys.argv[2] try: print(host) - ip = socket.gethostbyname(host) + # gethostbyname() returns IPv4 address + ip = socket.gethostbyname(host) print("IP Address: ", ip) - except: + except socket.gaierror: print('-' *25) print("Hostname does not exist") From ab26d7321cbf0c9b24a403a1530b2938e73da344 Mon Sep 17 00:00:00 2001 From: Yashesvinee V <76458668+Yashesvinee@users.noreply.github.com> Date: Wed, 5 Oct 2022 13:22:46 +0530 Subject: [PATCH 6/6] Update README.md --- Python/IP-Hostname_Validator/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/IP-Hostname_Validator/README.md b/Python/IP-Hostname_Validator/README.md index 6857ddb03..a87d0cf9f 100644 --- a/Python/IP-Hostname_Validator/README.md +++ b/Python/IP-Hostname_Validator/README.md @@ -1,5 +1,5 @@ # IP/Hostname Validator -### Libraries used: +### Modules used: - ipaddress - Provides functions to create, manipulate and operate in IPv4 and IPv6 addresses and networks. - sys - Used to provide access to variables maintained by the interpreter. - socket - Provides functions and objects to build network applications for clients and servers. It helps access the BSD Socket interface.