Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting IP from request in Python

I have a Pythonic HTTP server that is supposed to determine client's IP. How do I do that in Python? Is there any way to get the request headers and extract it from there?

PS: I'm using WebPy.

like image 378
Alex Avatar asked Sep 08 '26 22:09

Alex


2 Answers

Use web.ctx:

class example:
    def GET(self):
        print web.ctx.ip

More info here

like image 106
Masci Avatar answered Sep 11 '26 10:09

Masci


web.env.get('REMOTE_ADDR')

like image 20
Richard Simões Avatar answered Sep 11 '26 12:09

Richard Simões