-
Notifications
You must be signed in to change notification settings - Fork 490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python script to check the validity of a given IP address #1368
Open
Yashesvinee
wants to merge
6
commits into
HarshCasper:master
Choose a base branch
from
Yashesvinee:addpythonscript
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5fa5e78
Add files via upload
Yashesvinee fce4830
Update and rename README.md.txt to README.md
Yashesvinee f72837f
Update README.md
Yashesvinee 8c2b699
Update README.md
Yashesvinee 34f9ced
Update main.py
Yashesvinee ab26d73
Update README.md
Yashesvinee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 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) | ||
|
||
### Author | ||
[Yashesvinee](https://github.com/Yashesvinee) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import ipaddress | ||
import socket | ||
import 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 ValueError: | ||
print('-' *25) | ||
print('IP is not valid') | ||
|
||
elif sys.argv[1]=="hostname": | ||
host = sys.argv[2] | ||
try: | ||
print(host) | ||
# gethostbyname() returns IPv4 address | ||
ip = socket.gethostbyname(host) | ||
print("IP Address: ", ip) | ||
except socket.gaierror: | ||
print('-' *25) | ||
print("Hostname does not exist") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically i think these aren't libraries, but instead modules of the standard library.