Skip to content
This repository was archived by the owner on Jul 29, 2022. It is now read-only.

Commit 8b60ea8

Browse files
committed
Update icanhazip to return IP supporting X-Forwarded-For headers
1 parent c0ea0b6 commit 8b60ea8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

icanhaz.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ def icanhazafunction():
9090
result = json.dumps(dict(request.headers))
9191
else:
9292
# The request is for *.icanhazip.com or something we don't recognize
93-
result = request.remote_addr
93+
# This method should pull the correct hop even with load balancers in the way
94+
# https://stackoverflow.com/questions/33818540/how-to-get-the-first-client-ip-from-x-forwarded-for-behind-nginx-gunicorn
95+
result = request.access_route[0]
9496
return Response("%s\n" % result, mimetype="text/plain", headers={'X-Your-Ip': request.remote_addr})
9597

9698

0 commit comments

Comments
 (0)