Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get client ip and port? #81

Open
tradercentric opened this issue Jan 18, 2022 · 1 comment
Open

How to get client ip and port? #81

tradercentric opened this issue Jan 18, 2022 · 1 comment

Comments

@tradercentric
Copy link

Is there a way to log the client ip and/or port on the request?

@JK-de
Copy link

JK-de commented Jul 17, 2022

'resp' is a stream-writer and has a function 'get_extra_info' which gives a dict with only one element: 'peername'. This hold a tuple with addr and port.
Example:

@app.route("/")
def index(req, resp):
   
    clinet_ip, client_port = resp.get_extra_info('peername')
    
    yield from picoweb.start_response(resp)
    yield from resp.awrite("Your IP address is ")
    yield from resp.awrite(clinet_ip)
    yield from resp.awrite(" on port ")
    yield from resp.awrite(str(client_port))

see source code of uasyncio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants