-
Notifications
You must be signed in to change notification settings - Fork 1
/
Client.py
47 lines (31 loc) · 961 Bytes
/
Client.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import socket
import sys
import threading
FL = []
def createClientSocket(port, timeout, host='127.0.0.1'):
sock = socket.socket()
try:
sock.settimeout(timeout)
sock.connect((host, port))
sock.send(bytes(str(port)+"-ok",'utf-8'))
data = sock.recv(1024)
if data.decode('utf-8') == (str(port)+"-OK"):
FL.append(int(port))
print("Port {} is open!\n".format(port))
sock.close()
except Exception as e:
print("Error port {0}: {1}\n".format(port, e))
return None
finally:
sock.close()
def scanRange(port_begin, port_end, host, client_timeout):
threads = list()
for i in range(port_begin, port_end):
x = threading.Thread(target=createClientSocket, args=(i, client_timeout, host,))
threads.append(x)
x.start()
for i in threads:
i.join()
return FL