When a user opens my page, a PHP client is called on page load. The client calls to python gearman worker.
In that python worker script I wanted to get users IP address. 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, rather than the user's IP.
You cannot get the IP of the user from the Python script. You can either get it from PHP, or pass it from your PHP script to your Python script when you call your job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With