Skip to content

Commit 8a78ca2

Browse files
authored
Merge pull request #62 from Ninjavin/port-scanner-ninjavin
Port-Scanner-Added
2 parents a64a9e8 + b2d0dd5 commit 8a78ca2

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

Port-Scanner/PortScanner.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import sys
2+
import socket
3+
from colorama import init, Fore
4+
5+
init(autoreset=True)
6+
7+
def getTarget():
8+
hostname = input("Enter the hostname: ")
9+
target = socket.gethostbyname(hostname)
10+
return target
11+
12+
def scan(target, port):
13+
try:
14+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
15+
socket.setdefaulttimeout(1)
16+
print(Fore.CYAN + f"Scanning port {port}...")
17+
if s.connect_ex((target, port)) == 0:
18+
print(Fore.BLUE + f"Port {port} is Open")
19+
else:
20+
print(Fore.BLUE + f"Port {port} is Close")
21+
s.close()
22+
except socket.gaierror:
23+
print(Fore.RED + "Check your hostname!")
24+
sys.exit()
25+
except KeyboardInterrupt:
26+
sys.exit()
27+
28+
def reservedPorts():
29+
target = getTarget()
30+
for port in range(1024):
31+
scan(target, port)
32+
33+
def scanAllPorts():
34+
target = getTarget()
35+
for port in range(65536):
36+
scan(target, port)
37+
38+
def scanAPort():
39+
target = getTarget()
40+
port = int(input("Enter the port you want to scan: "))
41+
scan(target, port)
42+
43+
def criticalPorts():
44+
criticalPorts = [15, 20, 21, 22, 23, 25, 49, 50, 51, 53, 67, 68, 69, 79, 80, 88, 110, 111, 119, 123, 135, 137, 138, 139, 143, 161, 389, 443, 445, 500, 520, 546, 547, 636, 993, 995, 1512, 1701, 1720, 1723, 1812, 1813, 3306, 3389, 5004, 5005, 5060, 5061, 5900, 8080]
45+
target = getTarget()
46+
for port in criticalPorts:
47+
scan(target, port)
48+
49+
while True:
50+
print()
51+
print("-" * 22, "MENU", "-" * 22)
52+
print("Press 1 for Reserved Ports")
53+
print("Press 2 to scan all the ports")
54+
print("Press 3 for Critical Ports")
55+
print("Press 4 to scan a particular port")
56+
print("-" * 50)
57+
58+
choice = int(input(Fore.GREEN + "Enter the menu option: "))
59+
60+
if choice == 1:
61+
reservedPorts()
62+
elif choice == 2:
63+
scanAllPorts()
64+
elif choice == 3:
65+
criticalPorts()
66+
elif choice == 4:
67+
scanAPort()
68+
else:
69+
print("\nInvalid Choice. Enter a valid option!")

Port-Scanner/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Port Scanner
2+
3+
## How to Run?
4+
5+
* Download this folder in your system.
6+
* `cd` into the folder.
7+
* Install dependencies by running `pip install -r requirements.txt`
8+
* Run `python3 PortScanner.py`
9+
10+
## Output
11+
12+
![image](images/portscanner1.png)
13+
![image](images/portscanner2.png)

Port-Scanner/images/portscanner1.png

43.7 KB
Loading

Port-Scanner/images/portscanner2.png

37.7 KB
Loading

Port-Scanner/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
colorama==0.4.3

0 commit comments

Comments
 (0)