JAVA traffic flushing tool, So Easy !, Javaeasy

Source: Internet
Author: User

JAVA traffic flushing tool, So Easy !, Javaeasy

CSDN has recently changed its rules, making it increasingly uncomfortable. The quality of articles recommended to the homepage is no longer limited, and the quality of articles on the homepage is suddenly reduced. This message is seen in the official blog QQ group. The source is very reliable, but CSDN has not published an announcement yet, or it may not be necessary to send an announcement again. I think this method damages both the blog author and readers. For details, refer to my CSDN blog, http://blog.csdn.net/zhang5476499/article/details/53225133. So I wrote a slightly suggested Article overnight last night. In order to make the official site look boring today, I wrote a blog traffic flushing tool and pushed it directly to the rankings.

 

 

If possible, I also want to push the weekly or monthly rankings so that the official team can pay attention to users' feelings. Now, let's talk about technology. I never thought it was so easy to write this thing. Maybe you can write a more powerful tool.

Let's take a look at the principles of CSDN's blog access statistics:

When a client initiates a request to the server, each ip address is counted once. The three clients refer to three different ip addresses. In addition, accessing the same article by ip address within a certain period of time can only be regarded as one access volume. The same ip address Accesses Different articles in the same blog within a certain period of time. The number of accessed articles + 1.

After guiding the simple principle of appeal, I will try to solve the problem.

First, prepare a large number of ip proxies. One hundred degrees, a lot of resources are coming out. In this age, Lei Feng was quite a lot. I chose this ip proxy website and provided api call interfaces. The call address is:

Http://www.xicidaili.com/api

Next, introduce the jar package we need. Here we only need a jsoup package. Don't be scared by the jsoup term. Below I will post my blog and talk about how this buddy works.

jsoup-1.8.1.jar

Next, write a java bean that encapsulates the ip class. In fact, you can leave it empty and put it directly in the String [] array. However, in this case, it is convenient to retrieve the bean when the proxy calls it.

 1 public class MyIp { 2  3     private String address; 4      5     private String port; 6  7     public String getAddress() { 8         return address; 9     }10 11     public void setAddress(String address) {12         this.address = address;13     }14 15     public String getPort() {16         return port;17     }18 19     public void setPort(String port) {20         this.port = port;21     }22 }

The main tool used to call this interface is jsoup. I recommend my blog, http://blog.csdn.net/zhang5476499/article/details/52205150. Of course, you can also use httpClient and other tools to get the content of the webpage. The java code is implemented as follows:

Public static List <MyIp> getIp (String url) {List <MyIp> ipList = null; try {// 1. initiate a get request to the ip proxy address to obtain the proxy's ip Document doc = Jsoup. connect (url ). userAgent ("Mozilla "). cookie ("auth", "token "). timeout (3000 ). get (); // 2, resolve the obtained IP address to the String ipStr = doc. body (). text (). trim (). toString (); // 3. use a regular expression to cut all ip strings [] ips = ipStr. split ("\ s +"); // 4. the ip String obtained through loop traversal is encapsulated into the bean ipList of MyIp = new ArrayList <MyIp> (); for (final String ip: ips) {MyIp myIp = new MyIp (); string [] temp = ip. split (":"); myIp. setAddress (temp [0]. trim (); myIp. setPort (temp [1]. trim (); ipList. add (myIp) ;}} catch (IOException e) {System. out. println ("loading document crude");} return ipList ;}

Note that the get request is used when the api calls this page. Now, if you have obtained the ip address of the 100 Proxy from the api, you can set the proxy. The main code for setting the proxy is as follows:

1      System.setProperty("http.maxRedirects", "50");2      System.getProperties().setProperty("proxySet", "true");3      System.getProperties().setProperty("http.proxyHost", myIp.getAddress());4      System.getProperties().setProperty("http.proxyPort", myIp.getPort());

The next step is to loop through these obtained proxy ip addresses. Each time a proxy is set up, a request is sent to the blog address.

1 public static void main (String [] args) {2 // 1. to request an http Proxy address api, obtain the desired proxy IP address 3 String url = "http://api.xicidaili.com/free2016.txt"; 4 List <MyIp> ipList = getIp (url); 5 String blogUrl = ""; 6 then SC = new then (System. in); 7 8 System. out. print ("Enter the article address:"); 9 blogUrl = SC. nextLine (); 10 System. out. print ("Please input a multiple of the rounds of refreshing (x100):"); 11 int time = SC. nextInt (); 12 int count = 0; 13 14 for (int I = 0; I <ti Me; I ++) {15 // 2. set ip proxy 16 for (final MyIp myIp: ipList) {17 System. setProperty ("http. maxRedirects "," 50 "); 18 System. getProperties (). setProperty ("proxySet", "true"); 19 System. getProperties (). setProperty ("http. proxyHost ", myIp. getAddress (); 20 System. getProperties (). setProperty ("http. proxyPort ", myIp. getPort (); 21 22 try {23 Document doc = Jsoup. connect (blogUrl) 24. userAgent ("Mozilla") 25. cookie ("au Th "," token ") 26. timeout (3000) 27. get (); 28 if (doc! = Null) {29 count ++; 30 logger.info ("successful refresh times:" + count); 31} 32} catch (IOException e) {33 logger. error (myIp. getAddress () + ":" + myIp. getPort () + "error"); 34} 35} 36} 37}

This is almost the end of proxy writing. In fact, it does not require any advanced technology to fl traffic.

Complete the tool, here free download, code for reference only: http://download.csdn.net/detail/zhang5476499/9687448

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.