Created
December 24, 2019 18:42
-
-
Save BobbyBabazadeh/470fe4dbc03274841f401dd4be868044 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get user real ip address in Python3.x | |
import socket | |
def get_real_ip_addr(request): | |
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') | |
remote_addr = request.META.get('REMOTE_ADDR') | |
if x_forwarded_for: | |
ip = x_forwarded_for.split(' ,')[0] | |
elif remote_addr: | |
ip = remote_addr | |
else: | |
ip = request.META.get('AR_REAL_IP') | |
return ip | |
ip = get_real_ip_addr(request) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment