本文整理汇总了Python中IP类的典型用法代码示例。如果您正苦于以下问题:Python IP类的具体用法?Python IP怎么用?Python IP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cheungssh_login
def cheungssh_login(request):
info={"msgtype":"ERR","content":"","auth":"no"}
client_ip=request.META['REMOTE_ADDR']
print '登录:',client_ip
try:
print IP.find(client_ip)
except Exception,e:
print '不能解析IP'
示例2: iploc
def iploc():
# get client real ip
ip = request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
# FIXME: get the client: os type, os version, app version
loc = None
country = province = city = None
is_success = True
loc_d = None
try:
loc = IP.find(ip)
if loc:
tmp = loc.split()
if len(tmp) == 3:
(country, province, city) = tmp
elif len(tmp) == 2:
(country, province) = tmp
elif len(tmp) == 1:
country = tmp[0]
loc_d = {'country': country,
'province': province,
'city': city}
except:
is_success = False
loc_d = None
res = json.dumps({"success": is_success, "data": loc_d})
current_app.logger.debug(ip)
current_app.logger.debug(res)
return res
示例3: login_auth_check
def login_auth_check(request, *args, **kws):
callback = request.GET.get("callback")
info = {}
info["accesstime"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
info["URL"] = "%s?%s" % (request.META["PATH_INFO"], request.META["QUERY_STRING"])
info["IP"] = request.META["REMOTE_ADDR"]
info["IPLocat"] = IP.find(info["IP"])
isAuth = False
if request.user.is_authenticated():
info["username"] = request.user.username
isAuth = True
else:
info["username"] = "非认证用户"
login_record = cache.get("login_record")
if login_record:
login_record.append(info)
else:
login_record = [info]
if isRecord:
cache.set("login_record", login_record, 86400000)
if isAuth:
return func(request, *args, **kws)
else:
backinfo = {"msgtype": "login"}
backinfo = json.dumps(backinfo)
if callback:
info = "%s(%s)" % (callback, backinfo)
else:
info = "%s" % (backinfo)
return HttpResponse(info)
示例4: login_auth_check
def login_auth_check(request,*args,**kws):
if request.method=='POST':
request_content=request.POST
else:
request_content=request.GET
callback=request.GET.get('callback')
info={}
info['accesstime']=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
info['URL']= "%s?%s" %(request.META['PATH_INFO'],request.META['QUERY_STRING'])
info['IP']=request.META['REMOTE_ADDR']
info['page']=page
info['request_content']=request_content
info['IPLocat']=IP.find(info['IP'])
isAuth=False
if request.user.is_authenticated():
info["username"]=request.user.username
isAuth=True
else:
info["username"]="非认证用户"
login_record=cache.get('login_record')
if not login_record:login_record=[]
login_record.insert(0,info)
if isRecord:
cache.set('login_record',login_record,8640000000)
if isAuth:
return func(request,*args,**kws)
else:
backinfo={'msgtype':'login'}
backinfo=json.dumps(backinfo)
if callback:
info="%s(%s)" % (callback,backinfo)
else:
info="%s" % (backinfo)
return HttpResponse(info)
示例5: show_ip_limit
def show_ip_limit(request):
info={"msgtype":"ERR","content":[]}
callback=request.GET.get('callback')
R=cache.master_client
ip_limit_list=[]
for t in R.keys():
if re.search(':1:fail\.limit.*',t):
ip=re.sub(':1:fail\.limit\.','',t)
ip_time=cache.get('fail.limit.%s' % (ip))
ip_threshold_r=cache.get('ip.threshold')
ip_threshold=lambda x:x if x is not None else 4
ip_threshold=ip_threshold(ip_threshold_r)
if ip_time> ip_threshold:
ip_status="已锁定"
else:
ip_status="未超过阈值"
ip_limit={"ip":ip,"ip-locate":IP.find(ip),"time":ip_time,"status":ip_status}
ip_limit_list.append(ip_limit)
info["content"]=ip_limit_list
info["msgtype"]="OK"
info=json.dumps(info,encoding="utf-8",ensure_ascii=False)
if callback is None:
info=info
else:
info="%s(%s)" % (callback,info)
response=HttpResponse(info)
response["Access-Control-Allow-Origin"] = "*"
response["Access-Control-Allow-Methods"] = "POST"
response["Access-Control-Allow-Credentials"] = "true"
return response
示例6: findaddress
def findaddress(t, user_id, ip):
'''t=1:注册时查找ip t=2:兑换时查找ip'''
import IP
ip_address = IP.find(ip)
mysql = torndb.Connection(**config['mysql'])
if t == 1:
mysql.execute( "UPDATE `users` set `ip_address`=%s WHERE `uid`=%s", ip_address, user_id)
示例7: add_black_cmd
def add_black_cmd(request):
info={"msgtype":"ERR"}
cmd=request.GET.get('cmd')
callback=request.GET.get('callback')
black_cmd_list=cache.get('black.cmd.list')
create_user=request.user.username
create_time=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
client_ip=request.META['REMOTE_ADDR']
IP_locate=IP.find(client_ip)
id=str(random.randint(90000000000000000000,99999999999999999999))
CMD={
"id":id,
"owner":create_user,
"createtime":create_time,
"ip":client_ip,
"IPlocate":IP_locate,
"cmd":cmd
}
if black_cmd_list is None:black_cmd_list=[]
black_cmd_list.insert(0,CMD)
cache.set('black.cmd.list',black_cmd_list,8640000000)
info["msgtype"]="OK"
info["cid"]=id
info=json.dumps(info,encoding='utf-8',ensure_ascii=False)
if callback is None:
info=info
else:
info="%s(%s)" % (callback,info)
response=HttpResponse(info)
response["Access-Control-Allow-Origin"] = "*"
response["Access-Control-Allow-Methods"] = "POST"
response["Access-Control-Allow-Credentials"] = "true"
return response
示例8: get
def get(self):
r = self.get_argument('r', '')
if not r:
self.write('参数错误')
return
openid = utils.decrypt(r)
user_agent = self.request.headers.get('User-Agent', '')
platform = utils.get_platform(user_agent)
# 判断用户系统是否已知
user_info = users.get_info(openid)
if not user_info['platform']:
ip = self.request.remote_ip
ip_address = IP.find(ip)
users.set_ip(openid, ip, ip_address, platform)
if user_info['status'] == -2:
self.write("非法用户")
return
if platform == 2:
url = urlparse.urljoin(constants.SITE_BASEURL, 'v1/applist/goandroid')
self.redirect(url, False, 302)
return
aes = AESCipher()
r = aes.encode(openid)
url = 'http://w.ymapp.com/wx/ios/lists.html?r=%s' % r
#url = 'http://au.youmi.net/wx/ios/lists.html?r=%s' % r
self.redirect(url, False, 302)
示例9: login_auth_check
def login_auth_check(request,*args,**kws):
callback=request.GET.get('callback')
info={}
info['accesstime']=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
info['URL']= "%s?%s" %(request.META['PATH_INFO'],request.META['QUERY_STRING'])
info['IP']=request.META['REMOTE_ADDR']
info['IPLocat']=IP.find(info['IP'])
isAuth=False #默认为认证不通过,简化下面else的重写
if request.user.is_authenticated():
info["username"]=request.user.username
isAuth=True
else:
info["username"]="非认证用户"
#####写入redis ,该值为list,因为username是重复的, 如果用dict,记录会被覆盖
login_record=cache.get('login_record')
if login_record:
login_record.append(info)
else:
login_record=[info]
if isRecord:
cache.set('login_record',login_record,86400000) #写入redis
#####写入redis
if isAuth:
return func(request,*args,**kws)
else:
backinfo={'msgtype':'login'}#重写信息,该信息是返回给web的,不影响后台的info记录
backinfo=json.dumps(backinfo)
if callback:
info="%s(%s)" % (callback,backinfo)
else:
info="%s" % (backinfo)
return HttpResponse(info)
示例10: sort_proxyip
def sort_proxyip(pool):
result = {
"all": set(),
"china": set(),
"foreign": set(),
"high_anonymous": set(),
"low_anonymous": set(),
"non_anonymous": set(),
}
for ip in pool:
# country
info = IP.find(ip[0]).strip().replace("\t", "-")
ip_ = ip + (info,)
result["all"].add(ip_)
if info.startswith("中国"):
result["china"].add(ip_)
else:
result["foreign"].add(ip_)
# anonymous
if ip[2] == 3:
result["high_anonymous"].add(ip_)
elif ip[2] == 2:
result["low_anonymous"].add(ip_)
else:
result["non_anonymous"].add(ip_)
return result
示例11: writeFileLine
def writeFileLine(ip):
ports = r_client.sort(address_10(ip))
if ports:
port_list = []
port_list.append([x.decode("utf-8") for x in ports])
line = ip + "\t" + "[" + ",".join(port_list[0]) + "]\t" + IP.find(ip) + "\n"
ip_data.writelines(line)
示例12: ip2geo
def ip2geo(ip):
try:
city = IP.find(str(ip))
if city:
city.encode('utf-8')
else:
city=''
except Exception, e:
city = ''
示例13: cheungssh_login
def cheungssh_login(request):
info={"msgtype":"ERR","content":"","auth":"no"}
logintime=time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
client_ip=request.META['REMOTE_ADDR']
limit_ip='fail.limit.%s'%(client_ip)
ip_threshold_r=cache.get('ip.threshold')
ip_threshold=lambda x:x if x is not None else 4
ip_threshold=ip_threshold(ip_threshold_r)
if cache.has_key(limit_ip):
if cache.get(limit_ip)>ip_threshold:
info['content']="无效登陆"
cache.incr(limit_ip)
cache.expire(limit_ip,8640000)
info=json.dumps(info)
return HttpResponse(info)
if request.method=="POST":
username = request.POST.get("username", '非法用户名')
password = request.POST.get("password", False)
print username,password,request.POST
user=authenticate(username=username,password=password)
if user is not None:
if user.is_active:
print "成功登陆"
login(request,user)
request.session["username"]=username
info["msgtype"]="OK"
info['auth']="yes"
info['content']="成功登录"
request.session.set_expiry(0)
if cache.has_key(limit_ip):cache.delete(limit_ip)
print request.COOKIES,request.session.keys(),request.session['_auth_user_id']
info['sid']=str(request.session.session_key)
else:
info["content"]="用户状态无效"
print info["content"]
else:
if cache.has_key(limit_ip):
cache.incr(limit_ip)
else:
cache.set(limit_ip,1,3600)
info["content"]="用户名或密码错误"
info["IP"]=client_ip
info["IP-Locate"]=IP.find(client_ip)
info["username"]=username
info["logintime"]=logintime
redis_to_redis.set_redis_data('sign.record',json.dumps(info,encoding='utf-8',ensure_ascii=False))
else:
info["content"]="No Get"
info=json.dumps(info,encoding="utf-8",ensure_ascii=False)
response=HttpResponse(info)
response["Access-Control-Allow-Origin"] = "*"
response["Access-Control-Allow-Methods"] = "POST"
response["Access-Control-Allow-Credentials"] = "true"
return response
示例14: IP2city
def IP2city(geo):
try:
city=IP.find(str(geo))
if city:
city=city.encode('utf-8')
else:
return None
except Exception,e:
return None
示例15: ip2city
def ip2city(ip):
try:
city = IP.find(str(ip))
if city:
city = city.encode('utf-8')
else:
return None
except Exception, e:
return None