File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed 
ethical-hacking/port_scanner Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change 11import  argparse 
22import  socket  # for connecting 
3+ from  colorama  import  init , Fore 
34
4- from  threading  import  Thread 
5+ from  threading  import  Thread ,  Lock 
56from  queue  import  Queue 
67
8+ # some colors 
9+ init ()
10+ GREEN  =  Fore .GREEN 
11+ RESET  =  Fore .RESET 
12+ GRAY  =  Fore .LIGHTBLACK_EX 
13+ 
714# number of threads, feel free to tune this parameter as you wish 
815N_THREADS  =  200 
916# thread queue 
1017q  =  Queue ()
18+ print_lock  =  Lock ()
1119
1220def  port_scan (port ):
1321    """ 
@@ -17,9 +25,11 @@ def port_scan(port):
1725        s  =  socket .socket ()
1826        s .connect ((host , port ))
1927    except :
20-         print (f"{ host :15} { port :5}  , end = '\r ' )
28+         with  print_lock :
29+             print (f"{ GRAY } { host :15} { port :5} { RESET }  , end = '\r ' )
2130    else :
22-         print (f"{ host :15} { port :5}  )
31+         with  print_lock :
32+             print (f"{ GREEN } { host :15} { port :5} { RESET }  )
2333    finally :
2434        s .close ()
2535
Original file line number Diff line number Diff line change 11import  socket  # for connecting 
2+ from  colorama  import  init , Fore 
3+ 
4+ # some colors 
5+ init ()
6+ GREEN  =  Fore .GREEN 
7+ RESET  =  Fore .RESET 
8+ GRAY  =  Fore .LIGHTBLACK_EX 
29
310def  is_port_open (host , port ):
411    """ 
@@ -10,7 +17,7 @@ def is_port_open(host, port):
1017        # tries to connect to host using that port 
1118        s .connect ((host , port ))
1219        # make timeout if you want it a little faster ( less accuracy ) 
13-         #  s.settimeout(0.2)
20+         s .settimeout (0.2 )
1421    except :
1522        # cannot connect, port is closed 
1623        # return false 
@@ -24,6 +31,6 @@ def is_port_open(host, port):
2431# iterate over ports, from 1 to 1024 
2532for  port  in  range (1 , 1025 ):
2633    if  is_port_open (host , port ):
27-         print (f"[+] { host } { port }  )
34+         print (f"{ GREEN } { host } { port } { RESET }  )
2835    else :
29-         print (f"[!] { host } { port }  , end = "\r " )
36+         print (f"{ GRAY } { host } { port } { RESET }  , end = "\r " )
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments