Skip to content
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

Added port scanning python script #1409

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Contributors.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

{
"id": 348,
"fullname": "Smit Shah",
"username": "https://github.com/smit-sms"
}

<!DOCTYPE html>
<html lang="en">

Expand Down Expand Up @@ -1931,11 +1938,15 @@
"username": "https://github.com/rohitsingh2k"
},
{

"id":354,
"fullname": "Soumalya Mukherjee",
"username": "https://github.com/SoumalyaM"
"id":354,
"fullname": "Soumalya Mukherjee",
"username": "https://github.com/SoumalyaM"
},
{
"id":355,
"fullname": "Smit Shah",
"username": "https://github,com/smit-sms"
}
];


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'''
Author: smit-sms
'pip install pyfiglet' to see the ascii banner

USAGE
- Run the script by 'python port_scanner.py <url>'
- Replace the <url> with the URL of your choice, for eg. 'python port_scanner.py 127.0.0.1'
'''

# Importing the libraries
import pyfiglet
import sys
import socket
from datetime import datetime

# Printing the Ascii Banner
ascii_banner = pyfiglet.figlet_format("PORT SCANNER")
print(ascii_banner)

# Defining a target
if len(sys.argv) == 2:
# Translate hostname to IPv4 Address
target = socket.gethostbyname(sys.argv[1])
else:
print("Invalid amount of Argument")

print(" -" * 50)
print(" Scanning Target: " + target)
print(" Scanning started at: " + str(datetime.now()))
print(" -" * 50)

try:
# Recursively scan ports between 1 to 65,535
for port in range(1, 65535):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setdefaulttimeout(1)

# Returns an error indicator
result = s.connect_ex((target,port))
if result == 0:
print("\nPort {} is open.".format(port))
s.close()

except KeyboardInterrupt:
print("\n Exiting Program.")
sys.exit()
except socket.gaierror:
print("\n Hostname Could Not Be Resolved. Please try again with other Hostname.")
sys.exit()
except socket.error:
print("\n Server not responding. Please try again after sometime.")
sys.exit()