-
Notifications
You must be signed in to change notification settings - Fork 90
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
Using django-ipware get_client_ip instead of get_real_ip #45
Comments
@shadinaif Version 1 was simple and just wanted to get your the first routable IP address it found so users could identify clients uniquely. Version 2 on the other hand, allows the advanced users to pass in the The default behavior is to find the As for
Feel free to switch to version two. Closing the issue, but feel free to reopen if you feel that you have found a bug in version 2. |
Thank you @un33k 👍 |
The above explanation is a bit incomplete. If I read the code right, it stops on the first public IP, so if you are coming from a local private network, then get_client_ip will return based on the lowest priority header. Not necessarily a problem, but not an obvious change from the previous version. Just had to fix our test cases :) |
@kleptog Moving from 1.x to 2.x was a breaking change and the behavior changed as well. Therefore your test cases that were for 1.x needed to also changed. Hope this helps, |
@kleptog django-ipware is on its way to being deprecated. With that said, I have a python package that is going to replace it. Have a look at python-ipware and if works for you switch to it. Feedback is welcomed. |
Please help!
Already asked in stackoverflow: https://stackoverflow.com/questions/52162711/using-django-ipware-get-client-ip-instead-of-get-real-ip
In django-ipware version 2.1 ; old
get_real_ip
function is deprecated. When I use the newget_client_ip
; my test units are not showing the same results. Means that the two functions do not behave the same.The following is an original test from django-ipware test unit (not mine)
The above works fine of course, but I want to ensure that using the new
get_client_ip
will give the same results (for a system upgrade purposes). But the test is actually failing the assertion:resulting:
AssertionError: '177.139.233.132' != '198.84.193.157'
After digging into the code, I found that the new
get_client_ip
is not iterating inside the meta likeget_real_ip
. It checks out the left-most ip (or right-most depending on the settings) and skips to the next meta if a Public IP is not foundMy question(s) now are:
How can I call
get_client_ip
in a way that returns the same ip returned byget_real_ip
? What is the logic behind changing the behavior of the function ? Should I trust the newget_client_ip
and forget aboutget_real_ip
, or keep using the deprecatedget_real_ip
and forget about the newget_client_ip
?????The text was updated successfully, but these errors were encountered: