-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheClient.py
More file actions
39 lines (31 loc) · 1.23 KB
/
TheClient.py
File metadata and controls
39 lines (31 loc) · 1.23 KB
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
import socket
from Python_proxy import *
class TheClient(object):
def __init__(self, **kwargs):
try:
self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
except socket.error:
print("Error when creating the socket")
self.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
# self.socket.bind((Client_Host,Client_Port))
# self.socket.listen(1)
def run_client(self,proxy_host,proxy_port,data):
print("Running client on %s"% Client_Host)
print("Connecting to "+str((proxy_host,proxy_port)))
addr = (proxy_host,proxy_port)
self.socket.connect(addr)
self.socket.send(data)
#self.socket.sendto(data,(proxy_host,proxy_port))
recv = self.socket.recv(1024)
recv = recv.decode('utf-8')
print("Receving: %s"% recv)
def main(self,proxy_host,proxy_port,data,count=5):
total = count
while count:
count-=1
print("Turn %d:"%(total-count))
self.run_client(proxy_host,proxy_port,data)
client = TheClient()
data = Server_Host+' '+str(Server_Port)+' '+ "I_want_to_connect_to_you."
data_bytes = data.encode('utf-8')
client.main(Host,Port,data_bytes)