mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-23 04:20:27 +00:00
UPdate some
This commit is contained in:
@@ -10,16 +10,15 @@ from .models import LoginLog
|
||||
|
||||
def validate_ip(ip):
|
||||
try:
|
||||
ipaddress.ip_address(ip)
|
||||
ipaddress.ip_address(ip.decode('utf-8'))
|
||||
return True
|
||||
except ValueError:
|
||||
pass
|
||||
print('valid error')
|
||||
return False
|
||||
|
||||
|
||||
def write_login_log(username, name='', login_type='W',
|
||||
terminal='', login_ip='', user_agent=''):
|
||||
print(login_ip)
|
||||
if not (login_ip and validate_ip(login_ip)):
|
||||
login_ip = '0.0.0.0'
|
||||
if not name:
|
||||
@@ -29,11 +28,11 @@ def write_login_log(username, name='', login_type='W',
|
||||
terminal=terminal, login_city=login_city, user_agent=user_agent)
|
||||
|
||||
|
||||
def get_ip_city(ip, timeout=3):
|
||||
def get_ip_city(ip, timeout=10):
|
||||
# Taobao ip api: http://ip.taobao.com//service/getIpInfo.php?ip=8.8.8.8
|
||||
# Sina ip api: http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=8.8.8.8&format=js
|
||||
|
||||
url = 'http://ip.taobao.com//service/getIpInfo.php?ip=' + ip
|
||||
url = 'http://ip.taobao.com/service/getIpInfo.php?ip=' + ip
|
||||
r = requests.get(url, timeout=timeout)
|
||||
city = 'Unknown'
|
||||
if r.status_code == 200:
|
||||
|
Reference in New Issue
Block a user