Answer the question
In order to leave comments, you need to log in
How to make the inscription about the end of the program output only after the end of the work, and not in the process?
Wrote a very primitive but multi-threaded port scanner that checks if a port is open or not.
The problem is this:
That is, the program first displays a completion message, and then displays the results of its work.
Here is the code:
import socket
import sys
import threading
import requests, shutil, os
host = input('IP or host name: ')
print('--------------------------------------')
print('#########')
print('#Scaning#')
print('#########' + '\n')
def PortCheck(port):
# Запускаем проверку порта
s = socket.socket()
s.settimeout(1)
try:
s.connect((host, port))
except socket.error:
pass
else:
s.close
print(str(port) + ' is open' + '\n')
ports = [20, 21, 22, 23, 25, 42, 43, 53, 67, 69, 80, 110,
115, 123, 137, 138, 139, 143, 161, 179, 443, 445,
514, 515, 993, 995, 1080, 1194, 1433, 1702, 1723,
3128, 3268, 3306, 3389, 5432, 5060, 5900, 5938, 8080, 10000, 20000]
for port in ports:
threading.Thread(target=PortCheck, args = [port]).start()
print('--------------------------------------')
input('Process ended. Press Enter.' + '\n')
Answer the question
In order to leave comments, you need to log in
for port in ports:
threading.Thread(target=PortCheck, args = [port]).start()
for t in threading.enumerate(): # Получаем все потоки
if t != threading.current_thread(): # Если это не текущий поток
t.join() # Ожидаем его завершения
print('--------------------------------------')
input('Process ended. Press Enter.' + '\n')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question