- 论坛徽章:
- 0
|
某网站搞的投票活动,对每个IP进行了限制,两次投票之间必须要相隔一段指定的时间长度。这个没有办法绕过。但是我想用程序来自动投票,并且能够根据每次投票的时间间隔自动调整下一次的时间间隔:如果这一次投票失败,那么就将下一次的投票时间间隔加大一点,增长因子为1.1;如果本次投票成功,那么就将下一次的投票时间间隔缩小一点,缩小因子为0.9。同时,对时间间隔设置上限和下限,增长因子和缩小因子的作用不能导致时间间隔超过这个范围。不知道这样算不算自适应调整。为了避免产生不必要的麻烦。代码中凡是涉及到网站名称的地方都采用some-website代替。以下就是程序清单,采用python2.5+boa0.4.4完成。另外,借助了Windows下的ethereal对HTTP交互过程进行了分析。现在尚需要解决的一个问题是如何绕过IP地址的限制,这个我没能找到解决的办法,如果能每投一次票就改变一次IP地址,那么时间限制就迎刃而解了。
# -*- coding=gb2312 -*-
"""
vote online automation
just for proof-of-conception
all rights reserved by rockins
date:2007-1-27
"""
import sys
import os
import time
import string
import httplib
import urllib
TIME_LOWER_LIMIT = 60 * 10 + 30 # time lower limitation: 10.5 minutes
TIME_UPPER_LIMIT = 60 * 30 # time upper limitation: 30 minutes
INC_FACTOR = 1.1 # time increase factor
DEC_FACTOR = 0.9 # time decrease factor
def main():
time_interval = TIME_LOWER_LIMIT
success = 1
params = urllib.urlencode({'id_cata':11,'id_childcata':1568})
headers = {"Accept":"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, appliction/msword, */*",
"Referer":"http://some-website/cgi-bin/topbbs/pan_vote?id_cata=11",
"Accept-Language":"zh-cn",
"Content-Type":"application/x-www-form-urlencoded",
"Accept-Encoding":"gzip, deflate",
"User-Agent":"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)",
"Host":"some-website",
"Content-Length":"28",
#"Connection":"Keep-Alive",
#"Connection":"close",
"Cache-Control":"no-cache",
#"Cookie":"ct=1169832556296"
}
while True:
conn = httplib.HTTPConnection("some-website")
conn.request("POST","/cgi-bin/topbbs/pan_votesubmit", params, headers)
response = conn.getresponse()
data = response.read()
## print response.status, response.reason
## print data
conn.close()
if data.find("分享论坛,分享快乐!感谢您对本次活动的支持!") != -1:
print "第%d次投票成功,当前时间间隔为%d秒" %(success, time_interval)
if time_interval * DEC_FACTOR > TIME_LOWER_LIMIT:
time_interval = time_interval * DEC_FACTOR
success = success + 1
elif data.find("短时间内重复投票无效!") != -1:
print "本次投票失败,当前时间间隔为%d秒" %time_interval
if time_interval * INC_FACTOR TIME_UPPER_LIMIT:
time_interval = time_interval * INC_FACTOR
else:
print "未知错误,请联系作者"
sys.exit(-1)
time.sleep(time_interval)
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/270/showart_238904.html |
|