def log(): try: name = request.query.name salt = request.query.salt auth = request.query.auth if not hmac.compare_digest( auth, hmac.new(SERVER_SECRET.encode('utf-8'), salt.encode('utf-8'), digestmod='sha1').hexdigest()): raise NameError('Auth code incorrect.') messagesig = request.query.messagesig clienttime = request.query.clienttime host = request.query.host hostip = get_ip_address(request.query.hostip) reversehost = request.query.reversehost clienttime = datetime.strptime(clienttime, "%Y-%m-%dT%H:%M:%S.%f") servertime = datetime.utcnow() ip = get_ip_address(request.remote_addr) family = socket.AF_INET if ip.version == 4 else socket.AF_INET6 reverseclient = reverse_lookup(str(ip), family=family) dataset = dict(host=host, reversehost=reversehost, hostip=str(hostip), name=name, salt=salt, messagesig=messagesig, auth=auth, clienttime=clienttime, servertime=servertime, ip=str(ip), reverseclient=reverseclient, type='server') DATA[servertime.isoformat()] = dataset except Exception as ex: if DEBUG: tb = traceback.format_exc() return { 'success': False, 'exception': "{}: {}\n{}".format(type(ex), ex, tb) } else: return {'success': False, 'exception': "{}".format(ex)} # customizations of the dataset to be returned to client: del dataset['clienttime'] dataset['servertime'] = servertime.isoformat() dataset['ip'] = request.remote_addr dataset['hostip'] = request.query.hostip return {'success': True, 'data': dataset}
def __init__(self, config): """ip, port = self.svr.server_address""" self.config = config freq = int(self.config.get('network', 'freq')) self.set_tempo(freq) self.tcp_ip = get_ip_address() self.tcp_port = int(self.config.get('network', 'tcp_port')) # Création du Multicast self.multi_sender = MulticastIpSender(config) # Asynchronous Mixins TCP Server self.svr = None self.asynchronous_mixins_tcp_server() # Rythme du jeu self.event = None self.start_clock() self.test = 0 # Jeu self.game = Game() # FPS self.t = time() self.fps = 0
def main(logger): if cfg.PORT == 0: cfg.PORT = tools.pick_unused_port() MY_ADDR = "http://%s:%s"%(tools.get_ip_address(),cfg.PORT) t=Updater(cfg.SHARED_DIRS, cfg.SYNC_DELTA, cfg.USERNAME, cfg.PASSWORD, MY_ADDR, cfg.UPDATE_PATH, cfg.SIZE_THRESHOLD, logger=logger) t.setDaemon(1) t.start() bottle.TEMPLATE_PATH=[cfg.PUBLIC_ROOT] bottle._stderr = lambda x:logger.warn(x) bottle._stdout = lambda x:logger.info(x) bottle.run(server,host='0.0.0.0', server=bottle.CherryPyServer, port=cfg.PORT) t.shutdown() t.join()
def ip_send(self): tcp_ip = get_ip_address() tcp_port = int(self.config.get('network', 'tcp_port')) m = {"TCP Adress": (tcp_ip, tcp_port)} msg = dumps(m).encode("utf-8") while self.toujours: sleep(1) self.send_to(msg, self.multi_addr)
def __init__(self, config): self.config = config self.multi_ip = self.config.get('network', 'multi_ip') self.multi_port = int(self.config.get('network', 'multi_port')) self.multi_addr = self.multi_ip, self.multi_port self.tempo = time() self.count = 0 self.ip_server = get_ip_address() print("Envoi en multicast sur", self.multi_ip, self.multi_port)
async def ip(self, ctx): '''Get location of chamosbot server. ''' result = tools.get_ip_address().split('.')[-1] await ctx.channel.send(result)
def main(): parser = argparse.ArgumentParser(description='IP Logger Client') parser.add_argument('host', help='The hostname of the server to connect to') parser.add_argument('port', help='The port the server listens to') parser.add_argument('--shelvefile', help='A file to log to') parser.add_argument( '--name', '-n', help='The name of this client to transmit to the server', default='') parser.add_argument('--client-secret', '-c', help='The secret code of this client', required=True) parser.add_argument('--server-secret', '-s', help='The secret code of this client', required=True) args = parser.parse_args() if args.shelvefile: d = shelve.open(args.shelvefile) # Preparing the message to transmit data = {} data['name'] = args.name clienttime = datetime.utcnow() data['clienttime'] = clienttime.isoformat() data['host'] = args.host data['hostip'] = lookup(args.host) data['reversehost'] = reverse_lookup(args.host) data['salt'] = uuid.uuid4().hex data['auth'] = hmac.new(args.server_secret.encode('utf-8'), data['salt'].encode('utf-8'), digestmod='sha1').hexdigest() messagesigbytes = (data['salt'] + args.name + data['clienttime']).encode('utf-8') data['messagesig'] = hmac.new(args.client_secret.encode('utf-8'), messagesigbytes, digestmod='sha1').hexdigest() url_netloc = get_netloc(data['hostip'], args.port) url_query = "&".join(["{}={}".format(key, data[key]) for key in data]) split_url = urllib.parse.SplitResult(scheme='http', netloc=url_netloc, path='/log', query=url_query, fragment='') url = urllib.parse.urlunsplit(split_url) try: result = json.loads(urllib.request.urlopen(url).read().decode('utf-8')) except: sys.stderr.write( "Cannot connect to the server at http://{}:{}\n".format( args.host, args.port)) sys.exit(2) try: result['success'] if not result['success']: sys.stderr.write("No success. The following error occured:\n") sys.stderr.write(result['exception']) sys.stderr.write("\n") sys.exit(128) # customizations of the dataset to be logged locally: data['ip'] = get_ip_address(result['data']['ip']) data['reverseclient'] = result['data']['reverseclient'] data['clienttime'] = clienttime data['servertime'] = datetime.strptime(result['data']['servertime'], "%Y-%m-%dT%H:%M:%S.%f") data['type'] = 'client' if args.shelvefile: d[data['servertime'].isoformat()] = data except KeyError: sys.stderr.write("Response seems to be incorrect.\n") sys.stderr.write(str(result)) sys.stderr.write("\n") sys.exit(3) finally: if args.shelvefile: d.close()