-
Notifications
You must be signed in to change notification settings - Fork 0
/
Port Scanner.py
60 lines (41 loc) · 1.22 KB
/
Port Scanner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import threading
from queue import Queue
import time
import socket
from plyer import notification
# a print_lock is what is used to prevent "double" modification of shared variables.
# this is used so while one thread is using a variable, others cannot access
# it. Once done, the thread releases the print_lock.
# to use it, you want to specify a print_lock per thing you wish to print_lock.
print_lock = threading.Lock()
target = input("Enter target: ")
ip = socket.gethostbyname(target)
notification.notify(
title = "Port scanning:",
message=ip ,
timeout=60)
#error handling bois
def portscan(port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
con = s.connect((target,port))
with print_lock:
print('Port',port,": Open")
con.close()
except:
pass
def threader():
while True:
worker = q.get()
portscan(worker)
q.task_done()
q = Queue()
for x in range(30):
t = threading.Thread(target=threader)
t.daemon = True
t.start()
start = time.time()
# Ports 1-1000
for worker in range(1,1000):
q.put(worker)
q.join()