UPdate some

This commit is contained in:
ibuler
2016-11-14 19:28:21 +08:00
parent 419876b575
commit 8d358a7a68
11 changed files with 165 additions and 29 deletions

View File

@@ -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: