forked from Purusottamdas/HacktoberFest2020-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea7c70f
commit 2fd54c6
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import socket | ||
import threading | ||
from queue import Queue | ||
|
||
target= "127.0.0.1" #Write the ip address of target you want to scan | ||
queue=Queue() | ||
open_ports=[] | ||
|
||
def portscan(port): | ||
try: | ||
sock =socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
sock.connect((target, port)) | ||
return True | ||
except: | ||
return False | ||
|
||
def fill_queue(port_list): | ||
for port in port_list: | ||
queue.put(port) | ||
|
||
def worker(): | ||
while not queue.empty(): | ||
port=queue.get() | ||
if portscan(port): | ||
print("Port {} is open".format(port)) | ||
open_ports.append(port) | ||
|
||
port_list =range(1,1024) | ||
fill_queue(port_list) | ||
|
||
thread_list=[] | ||
for t in range(10): | ||
thread = threading.Thread(target=worker) | ||
thread_list.append(thread) | ||
|
||
for thread in thread_list: | ||
thread.start() | ||
|
||
for thread in thread_list: | ||
thread.join() | ||
|
||
print("Open ports are:", open_ports) | ||
|