def excu_search_v3(self, params): print(params) self.caseParam = params client = Client('172.20.17.67', 9090).setClass('Search').setMethod( 'getSearchStore_v3').getApi() # 连接服务器 params = params.encode('utf-8') result = client.getSearchData_v4(params) # 调用接口 print(result) self._result = result
def start_tr069_client(self, device): init = Init.Init() try: client = Client.Client() client.start() device.client_TR069_status = "Link to ACS ip:" + str( client.acs_ip) + " port " + str(client.acs_port) + " ...OK" return True except: device.client_TR069_status = "Fail connect to ACS ip" + str( client.acs_ip) + " port " + str(client.acs_port) return False return True
def HostGame( self ): #Host game function handles incoming connections notice hangs until all connections have been made self.reset(self.multiamtply) self.mapdir = self.multimapdir self.loadMap() self.GiveRegions() self.multiplayer = True self.isHosting = True self.PlayerId = 0 #Host = "192.168.1.134" #Port = 52521 Host = self.multiHost Port = self.multiPort sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind((Host, Port)) self.Players[0].name = "-Host- " + self.multiname while len(self.Clients) < len(self.Players) - 1: #wait for all clients print("Listening for a client") sock.listen(0) conn, addr = sock.accept() plname = conn.recv(4096).decode("windows-1252") newClient = Client(conn, addr) self.Clients.append(newClient) self.Players[len(self.Clients)].name = plname print("New client connected! as ", plname) print("All clients connected") self.INFBar = InfoBar(self.Players) thisState = self.getState() print("Current state got!") indexer = 0 for cl in self.Clients: #send map and game details to all players indexer = indexer + 1 cl.conn.send(indexer.to_bytes(32, "big")) print("id sent!") time.sleep(0.001) cl.conn.send(thisState.SerializeToString()) print("sent state to player", indexer) self.sock = sock self.ListenerThread = threading.Thread( target=self.ListenerThread) #listener for clients self.ListenerThread.start()
def main(): """ Main entrypoint of the program """ # get args passed by the command line args = Tools.init_args() # check for required binaries and root privileges and run server keypair generation and dir structure check Setup.check_prerequisits() Setup.start(WG_BASE_PATH, WG_CLIENT_BASE_PATH) # get final list of clients (ldap and local), server keypair and base vpn, and negotiate a vpn_subnet clients = ClientTools.get_client_list(args) server_pubkey, server_privkey = ServerTools.read_server_keys(WG_BASE_PATH) base, ip = Tools.get_base_ip(lastip_file) vpn_subnet = Tools.get_vpn_subnet(subnet_file) # build clients n_clients = len(clients) if n_clients > 65531: # we cannot manage more than this amount of clients, don't even try Logger.fatal( "You are trying to create more than 65531 peers. This exceeds the /16 VPN-Subnet and is " "not supported by WGGEN.") Logger.info(f"Will be creating {n_clients} peers") actual_clients = [] for i, client in enumerate(clients): # determine client path client_path = f"{WG_CLIENT_BASE_PATH}/{client}" try: os.makedirs(client_path) except OSError: pass # determine client vpn ip ip += 1 if ip > 254: base += 1 if base > 255: Logger.fatal( f"Ran out of VPN-Subnet Addresses at client {i} of {n_clients}" ) ip = 1 client_vpn_ip = f"{vpn_subnet}.{base}.{ip}" # generate client generated_client = Client(client_path, client, args.endpoint, args.dns, server_pubkey, args.access, client_vpn_ip) actual_clients.append(generated_client) if not generated_client.state: Logger.warn(f"Failed to create client: {client}") print(f"Creating clients: {int((i/(n_clients-1))*100)}%", end="\r") # save last ip on last client with open(lastip_file, 'w') as f: f.write(f"{base}.{ip}") print(f"\nCreated {n_clients} clients") # write client config files and server config file ClientTools.write_config_files(actual_clients) ServerTools.write_server_config(actual_clients, args, vpn_subnet, WG_BASE_PATH)
#!/usr/bin/python3 # -*- coding: utf-8 -*- import socket import sys import lib.init as Init import lib.Client.Client as Client init = Init.Init() init.config_file = '/home/leo/emualator/etc/device.conf' init.read_config() init.init_database() client = Client.Client() client.start() sys.exit()