@Macux
2017-11-23T10:17:19.000000Z
字数 1982
阅读 1089
工作
import redis
pool= redis.ConnectionPool(host='127.0.0.1', port=6379, db=0)
r = redis.StrictRedis(connection_pool=pool)
dict = {"16777216":'"16777471","DCH","AU","Australia","Queensland","Brisbane","Research Prefix for APNIC Labs"',
"16781312":'"16785407","DCH","JP","Japan","Tokyo","Tokyo","I2TS Inc."',
"16802923":'"16802923","VPN","JP","Japan","Shimane","Izumo","Energia Communications Inc."',
"3758080000":'"3758088191","DCH","KR","Korea, Republic of","Seoul-teukbyeolsi","Seoul","Netropy Co. Ltd"',
"3758092288":'"3758093311","DCH","HK","Hong Kong","Hong Kong (SAR)","Hong Kong","Metronet"',
"3758094336":'"3758095359","DCH","HK","Hong Kong","Hong Kong (SAR)","Hong Kong","Capital Online Data Service HK Co Ltd"',
"3758095872":'"3758096127","DCH","SG","Singapore","Singapore","Singapore","Marina Bay Sands Pte Ltd"',
"3758096128":'"3758096383","DCH","AU","Australia","Queensland","Brisbane","APNIC Pty Ltd"'}
# use a collection of hash to store providers data
r.hmset('ip2location',dict)
use a zset to index the max value of your ranges
r.zadd('ip2location:index',16777471,"16777216",
16785407,"16781312",
16802923,"16802923",
3758088191,"3758080000",
3758093311,"3758092288",
3758095359,"3758094336",
3758096127,"3758095872",
3758096383,"3758096128")
# 找出所有IP段右端点比当前IP大的最小的一个:默认是升序排列,所以取第一个即可
ip = 3232235787
# 如果这个IP段的左端点比当前IP小,即符合IP段条件,可以判断当前IP是否为高匿名IP
# 4294967295是IP转十进制的最大值,故作为范围查询的区间
leftDot = r.zrangebyscore('ip2location:index',min=ip,max=4294967295,start=0,num=1)
if int(leftDot) <= ip:
value = r.hget('ip2location',str(leftDot))
if value.find('DCH') == -1:
print 'Anonymity of current ip is high!'
else:
pass
else:
pass
代理IP安装反作弊优化升级开发进度:
- 每天定时自动下载ip库
- 脚本done;
- 下午已通过离线,今晚再测试一次;
- 测试保存路径:s3://mob-emr-test/3s_atf/
- 历史IP库处理方式:在s3上保留历史IP库,用日期区分,Redis中只保留最新的IP库
- 平均效率:70s
- 每天定时update redis
- 脚本done;
- 下午已通过离线,今晚再测试一次;
- 设置保险机制:如果检测到定时自动下载IP库失败,自动更新脚本会先重新下载,并打印是否下载成功和更新成功;
- 平均效率:全量更新时间为70s,增量更新时间会更短;
- 安装IP匿名判断
- 脚本Done;
- 离线测试通过;
- 正在使用10月全量安装数据进行测试;
- 过往测试的平均效率:0.02s;
- 历史channel-offer匿名IP安装占比统计
- 已统计完10月;
- 预计这周能统计完近三个月的数据
- 接下来的计划
- 本周完成离线代码测试;
- 本周完成离线数据统计;
- 本周完成在线反作弊框架代码学习,总结不懂的地方下周请教大家;
- 下周三之前做好在线测试准备工作;