Skip to content

Commit 66e46aa

Browse files
committed
Port-Scanner-Added
1 parent f6894b5 commit 66e46aa

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

Port-Scanner/PortScanner.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import sys
2+
import socket
3+
from colorama import init, Fore
4+
5+
init(autoreset=True)
6+
7+
def scanAPort():
8+
hostname = input("Enter the hostname: ")
9+
port = int(input("Enter the port you want to scan: "))
10+
target = socket.gethostbyname(hostname)
11+
12+
try:
13+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
14+
socket.setdefaulttimeout(1)
15+
16+
if s.connect_ex((target, port)) == 0:
17+
print(Fore.BLUE + f"Port {port} is open")
18+
else:
19+
print(Fore.BLUE + f"Port {port} is close")
20+
21+
22+
s.close()
23+
24+
except socket.gaierror:
25+
print(Fore.RED + "Check your hostname!")
26+
sys.exit()
27+
except KeyboardInterrupt:
28+
sys.exit()
29+
30+
def scanCommonPorts():
31+
commonPorts = [20,21,22,23,25,53,80,110,119,123,143,161,194,443,445,464,465,497,500,512,513,514,515,520,521,540,554,563,587,631,636,691,873,993,994,995,1080,1433,1434,1512,1701,1758,1759,1789,1812,1813,1985,2049,2053,2100,2401,2809,3130,3306,4321,4444,5002,5308,5549,6000,9876,10080,11371,11720,13720,13721,31337,33434]
32+
33+
hostname = input("Enter the hostname: ")
34+
target = socket.gethostbyname(hostname)
35+
36+
open_ports = []
37+
close_ports = []
38+
39+
for port in commonPorts:
40+
try:
41+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
42+
socket.setdefaulttimeout(1)
43+
44+
if s.connect_ex((target, port)) == 0:
45+
print(Fore.CYAN + f"Scanning port {port}...")
46+
open_ports.append(port)
47+
else:
48+
print(Fore.CYAN + f"Scanning port {port}...")
49+
close_ports.append(port)
50+
51+
s.close()
52+
53+
except socket.gaierror:
54+
print(Fore.RED + "Check your hostname!")
55+
sys.exit()
56+
except KeyboardInterrupt:
57+
sys.exit()
58+
59+
if(open_ports):
60+
print(Fore.GREEN + "These ports are Open: ")
61+
print(open_ports)
62+
if(close_ports):
63+
print(Fore.GREEN + "These ports are Close: ")
64+
print(close_ports)
65+
66+
while True:
67+
print()
68+
print("-" * 22, "MENU", "-" * 22)
69+
print("1. Look for a specific port in a server")
70+
print("2. Scan for some common ports in a server")
71+
print("3. Quit")
72+
print("-" * 50)
73+
74+
choice = int(input(Fore.GREEN + "Enter the menu option: "))
75+
76+
if choice == 1:
77+
scanAPort()
78+
elif choice == 2:
79+
scanCommonPorts()
80+
elif choice == 3:
81+
break
82+
else:
83+
print("\nInvalid Choice. Enter a valid option!")

Port-Scanner/README.md

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

Port-Scanner/images/portscanner1.png

43.7 KB
Loading

Port-Scanner/images/portscanner2.png

37.7 KB
Loading

0 commit comments

Comments
 (0)