1 if 'HTTP_X_FORWARDED_FOR' in request.META.keys():
2 ip = request.META['HTTP_X_FORWARDED_FOR']
3 else:
4 ip = request.META['REMOTE_ADDR']
5
6 ip_match_status = False
7 for whiteip in cpapp_obj.whiteiplist:
8 if ip == whiteip:
9 ip_match_status = True
10 break
11 elif '%' in whiteip:
12 newhiteip = whiteip.replace('%', '([01]{0,1}\d{0,1}\d|2[0-4]\d|25[0-5])')
13 if re.match(newhiteip, ip):
14 ip_match_status = True
15
16 if not ip_match_status:
17 raise MyException(*errcode.CLIENT_REQUEST_IP_LIMIT_ERR)