Created
December 7, 2014 13:11
-
-
Save legatoo/d2f5b811835281062618 to your computer and use it in GitHub Desktop.
Wechat vote using Tor and Pycurl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import pycurl | |
import time | |
from urllib import urlencode | |
from StringIO import StringIO | |
import re | |
from io import BytesIO | |
def refreshIP(): | |
print "Refreshing IP..." | |
try: | |
process = subprocess.Popen(['sudo','service','tor', 'restart'], shell=False, stdin=subprocess.PIPE,stdout=subprocess.PIPE) | |
process.stdin.write('hakunami\n') | |
process.stdin.flush() | |
stdout, stderr = process.communicate() | |
print 'Tor restart info: ', stdout | |
ipchecker = subprocess.Popen(['/usr/bin/GET', 'http://clientn.free-hideip.com/map/whatismyip.php', '-p', 'http://127.0.0.1:8118'], | |
shell=False, stdout=subprocess.PIPE) | |
stdout, stderr = ipchecker.communicate() | |
IP = re.search('\d+\.\d+\.\d+\.\d+',stdout) | |
if IP: | |
print 'Current using IP is: ', IP.group(0) | |
except Exception, ex: | |
print "Failed to Refresh IP.", ex | |
def vote(): | |
#storage = StringIO() | |
storage = BytesIO() | |
c = pycurl.Curl() | |
c.setopt(c.URL, 'http://ud.xian.qq.com/api/activity/10291/vote/user/35960143/iframe?callback=ACT.votebackbank') | |
c.setopt(pycurl.PROXY, '127.0.0.1:9050') | |
c.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5) | |
c.setopt(pycurl.WRITEFUNCTION, storage.write) | |
post_data = {'Pragma':'no-cache', | |
'Origin':'http://xian.qq.com', | |
'Accept-Encoding':'gzip, deflate', | |
'Accept-Language': 'en,en-US;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2,vi;q=0.2', | |
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4', | |
'Content-Type': 'application/x-www-form-urlencoded' , | |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', | |
'Cache-Control': 'no-cache', | |
'Referer': 'http://xian.qq.com/zt2014/2014festival/index.htm', | |
'Proxy-Connection': 'keep-alive', | |
'Content-Length': '0', | |
'Content-Type':'application/x-www-form-urlencoded' | |
} | |
# Form data must be provided already urlencoded. | |
postfields = urlencode(post_data) | |
# Sets request method to POST, | |
# Content-Type header to application/x-www-form-urlencoded | |
# and data to send in request body. | |
c.setopt(c.POSTFIELDS, postfields) | |
response = c.perform() | |
c.close() | |
response = storage.getvalue().decode('UTF-8') | |
#print response | |
if "\"retcode\":0" in response: | |
print "Vote Success." | |
else: | |
print "Vote Fail." | |
def operate(): | |
while(True): | |
refreshIP(); | |
for i in range(5): | |
vote() | |
time.sleep(15) | |
if __name__ == "__main__": | |
print "Vote for ReXian...." | |
operate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment