fix: login log get ipv6 error

pull/14569/head
Bai 2024-11-29 14:50:51 +08:00 committed by Bryan
parent fb634dca4c
commit 69a366978f
1 changed files with 4 additions and 1 deletions

View File

@ -158,7 +158,10 @@ def is_uuid(seq):
def get_request_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR', '').split(',')
if x_forwarded_for and x_forwarded_for[0]:
login_ip = x_forwarded_for[0].split(":")[0]
login_ip = x_forwarded_for[0]
if login_ip.count(':') == 1:
# format: ipv4:port (非标准格式的 X-Forwarded-For)
login_ip = login_ip.split(":")[0]
return login_ip
login_ip = request.META.get('REMOTE_ADDR', '')