4
4
5
5
init (autoreset = True )
6
6
7
- def scanAPort ():
7
+ def getTarget ():
8
8
hostname = input ("Enter the hostname: " )
9
- port = int (input ("Enter the port you want to scan: " ))
10
9
target = socket .gethostbyname (hostname )
10
+ return target
11
11
12
+ def scan (target , port ):
12
13
try :
13
14
s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
14
15
socket .setdefaulttimeout (1 )
15
-
16
+ print ( Fore . CYAN + f"Scanning port { port } ..." )
16
17
if s .connect_ex ((target , port )) == 0 :
17
- print (Fore .BLUE + f"Port { port } is open " )
18
+ print (Fore .BLUE + f"Port { port } is Open " )
18
19
else :
19
- print (Fore .BLUE + f"Port { port } is close" )
20
-
21
-
20
+ print (Fore .BLUE + f"Port { port } is Close" )
22
21
s .close ()
23
-
24
22
except socket .gaierror :
25
23
print (Fore .RED + "Check your hostname!" )
26
24
sys .exit ()
27
25
except KeyboardInterrupt :
28
26
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
27
36
- open_ports = []
37
- close_ports = []
28
+ def reservedPorts ():
29
+ target = getTarget ()
30
+ for port in range (1024 ):
31
+ scan (target , port )
38
32
39
- for port in commonPorts :
40
- try :
41
- s = socket . socket ( socket . AF_INET , socket . SOCK_STREAM )
42
- socket . setdefaulttimeout ( 1 )
33
+ def scanAllPorts () :
34
+ target = getTarget ()
35
+ for port in range ( 65536 ):
36
+ scan ( target , port )
43
37
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 )
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 )
65
48
66
49
while True :
67
50
print ()
68
51
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" )
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" )
72
56
print ("-" * 50 )
73
57
74
58
choice = int (input (Fore .GREEN + "Enter the menu option: " ))
75
59
76
60
if choice == 1 :
77
- scanAPort ()
61
+ reservedPorts ()
78
62
elif choice == 2 :
79
- scanCommonPorts ()
63
+ scanAllPorts ()
80
64
elif choice == 3 :
81
- break
65
+ criticalPorts ()
66
+ elif choice == 4 :
67
+ scanAPort ()
82
68
else :
83
69
print ("\n Invalid Choice. Enter a valid option!" )
0 commit comments