直接贴源码,python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
import json
import sys
import platform
#python 2
import os
reload(sys)
sys.setdefaultencoding('utf8')
def version_check():
version=platform.python_version()
v_h = version[0:1]
v_h = v_h.strip()
if v_h is "3":
print("python versoin is",version)
import importlib
importlib.reload(sys)
else:
import os
reload(sys)
sys.setdefaultencoding('utf8')
url = "http://ip.taobao.com/service/getIpInfo.php?ip="
def ip_find(ip):
data = urllib.urlopen(url + ip).read()
datadict=json.loads(data)
for oneinfo in datadict:
if "code" == oneinfo:
if datadict[oneinfo] == 0:
return datadict["data"]["country"] + datadict["data"]["region"