Get IP address of viewers in python

When a user opens my page, the PHP client is called on page load. The client turns to a python turner worker.

In this python worker script, I wanted to get the IP address of the users. I tried both

ip = ([(s.connect(('8.8.8.8', 80)), s.getsockname()[0], s.close())
    for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1])

      

and

urlopen('http://ip.42.pl/raw').read()

      

But this gives my server IP, not the user's IP.

+3


source to share


1 answer


You cannot get the user's IP address from a Python script. You can either get it from PHP or pass it from your PHP script to your Python script when calling your work.



+1


source







All Articles