Skip to content

Instantly share code, notes, and snippets.

@jtrent238
Created November 7, 2015 22:51
Show Gist options
  • Select an option

  • Save jtrent238/947704504818ec2c3a1d to your computer and use it in GitHub Desktop.

Select an option

Save jtrent238/947704504818ec2c3a1d to your computer and use it in GitHub Desktop.
StrawPoll Proxy Voter
<?php
set_time_limit(0);
class StrawPoll {
public function __construct() {
}
public function vote($id, array $votes, $amount = 10, $proxyList = null, $timeout = 5, $showErrors = true) {
$mh = curl_multi_init();
$chs = array();
if(is_file($proxyList)) {
$parts = pathinfo($proxyList);
$json = false;
if($parts['extension'] == 'json') {
$proxies = json_decode(file_get_contents($proxyList), true);
if($proxies) {
$json = true;
} else {
return 'Malformed JSON in ' . $proxyList;
}
} else {
$proxies = file($proxyList);
}
}
$post = array(
'id' => $id,
'votes' => $votes
);
$post = http_build_query($post);
$headers = array(
'Origin: http://strawpoll.me',
'If-None-Match: 6bbfd',
'X-Requested-With: XMLHttpRequest'
);
$loop = false;
if($amount == -1) {
$loop = true;
$amount = 25;
}
if(isset($proxies)) {
$amount = count($proxies);
}
$used = array();
for($i = 0; $i < $amount; $i++) {
$ch = $this->makeCurl('http://strawpoll.me/ajax/vote');
$chs[] = $ch;
if(isset($proxies)) {
if(count($proxies) < 1) {
if($showErrors) {
echo 'Out of proxies :(' . PHP_EOL;
}
break;
}
$key = array_rand($proxies);
$proxy = $proxies[$key];
unset($proxies[$key]);
$proxyType = CURLPROXY_HTTP;
if(!$json) {
$proxy = trim($proxy);
$parts = explode(':', $proxy);
if(isset($parts[0], $parts[1])) {
$proxyIP = $parts[0];
$proxyPort = $parts[1];
} else {
$i--;
continue;
}
if(isset($parts[2])) {
$proxyType = strtoupper($proxyType) == 'SOCKS5' ? CURLPROXY_SOCKS5 : CURLPROXY_HTTP;
}
} else if($json && isset($proxy['ip'], $proxy['port'])) {
$proxyIP = $proxy['ip'];
$proxyPort = $proxy['port'];
if(isset($proxy['type'])) {
$proxyType = strtoupper($proxy['type']) == 'SOCKS5' ? CURLPROXY_SOCKS5 : CURLPROXY_HTTP;
}
}
if(isset($used[$proxyIP])) {
$i--;
continue;
}
$used[$proxyIP] = true;
if(!filter_var($proxyIP, FILTER_VALIDATE_IP,
FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)
|| (!ctype_digit($proxyPort) || ($proxyPort < 0 || $proxyPort > 65535))) {
$i--;
continue;
}
curl_setopt_array($ch, array(
CURLOPT_PROXY => $proxyIP . ':' . $proxyPort,
CURLOPT_PROXYTYPE => $proxyType
));
}
curl_setopt_array($ch, array(
CURLOPT_POSTFIELDS => $post,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_REFERER => 'http://strawpoll.me/' . $id,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36',
CURLOPT_TIMEOUT => $timeout
));
curl_multi_add_handle($mh, $ch);
}
$running = null;
$votes = 0;
$j = 0;
$results = array();
do {
while(($exec = curl_multi_exec($mh, $running)) == CURLM_CALL_MULTI_PERFORM);
if($exec != CURLM_OK) {
break;
}
while($ch = curl_multi_info_read($mh)) {
$j++;
$ch = $ch['handle'];
$error = curl_error($ch);
if(!$error) {
$resp = curl_multi_getcontent($ch);
$out = json_decode($resp, true);
if(!isset($out['success'])) {
if($showErrors) {
echo 'Didn\'t vote. Invalid response.' . PHP_EOL;
var_dump($resp);
}
} else {
if($out['success'] == true) {
$votes++;
echo '[' . $votes . '] Voted' . PHP_EOL;
}
}
$results[] = $out;
} else {
$results[] = $error;
if($showErrors) {
echo $error . PHP_EOL;
}
}
curl_multi_remove_handle($mh, $ch);
curl_close($ch);
}
} while($running);
curl_multi_close($mh);
if($loop) {
$this->vote($id, $votes, $amount, $proxyList, $timeout);
return array('results' => $results, 'votes' => $votes);
}
return array('results' => $results, 'votes' => $votes, 'total' => $amount);
}
public function makeCurl($url) {
$cookie = dirname(__FILE__) . '/strawpoll.txt';
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEFILE => $cookie,
CURLOPT_COOKIEJAR => $cookie
));
return $ch;
}
}
$sp = new StrawPoll();
$votes = $sp->vote(1559802, array(1), 5000, 'proxies.txt', 30, false);
echo 'Successfully voted ' . $votes['votes'] . '/' . $votes['total'] . ' time(s)';
@wattuman

wattuman commented May 2, 2017

Copy link
Copy Markdown

How does this work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment