I am using Trio and how do I get the IP address of an already open socket?

117 Views Asked by At

This is a simple problem and Im sure there is an solution. I am trying to get the IP address of a socket which I have already connected to. I used trio.serve_tcp(handler, port) to create an server and now I want to know if someone is making thousands of connections to it but I need to know how to get the IP address of an accepted connection.

1

There are 1 best solutions below

0
On

if you accepted by a handler ProxyHandler()

def ProxyHandler(newclient):
   print('New connection from : '+repr(newclient.socket.getpeername()))

It was that easy.