-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathport_scanner3.py
44 lines (35 loc) · 949 Bytes
/
port_scanner3.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
import socket
import threading
from queue import Queue
# Thread queue
thread_queue = Queue()
def threader():
while True:
worker = thread_queue.get()
scan_port(worker)
thread_queue.task_done()
def scan_port(port):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(0.5)
result = s.connect_ex((target, port))
if result == 0:
print(f"Port {port} açık")
s.close()
except socket.error:
pass
def scan_all_ports(target):
for x in range(100): # Number of threads
t = threading.Thread(target=threader)
t.daemon = True
t.start()
for port in range(1, 65536):
thread_queue.put(port)
thread_queue.join()
def main():
global target
target = input("Hedef IP adresini girin: ")
target = socket.gethostbyname(target)
scan_all_ports(target)
if __name__ == "__main__":
main()