人若无名,便可专心练剑

 论坛 标签

java 提取xx论坛种子哈希

  |   0 评论   |   2,658 浏览

后期需引入多线程,目前速度有点慢,不过可以用了,后面改进吧


package org.c2y2.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HttpConnectTestCase{
	public static void main(String[] args) {
		try {
			File file = new File("/home/c2y2/enjoy.txt");
			if(!file.exists()){
				file.createNewFile();
			}
			FileOutputStream fileOutputStream = new FileOutputStream(file);
			String hashCode = "";
			String regex = "[a-f0-9]{43}";
			for (int i = 0; i < 1000; i++) {
				String urlString = "http://xx.xx.xx.xx/htm_data/2/1404/1081";
				if(i<10){
					urlString +="00"+String.valueOf(i);
				}else if(i>=10 && i<100){
					urlString +="0"+String.valueOf(i);
				}else{
					urlString +=String.valueOf(i);
				}
				urlString+=".html";
				URL url = new URL(urlString);
				System.out.println(i);
				String reponseString = regexGetString(url,regex);
				if(reponseString!=null && !reponseString.equals("")){
					hashCode+=reponseString+"\r\n";
				}
			}
			fileOutputStream.write(hashCode.getBytes());
			fileOutputStream.flush();
			fileOutputStream.close();
			System.out.println("结束========");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public static String regexGetString(URL url,String regex){
		//1419376984d84d9e5a056aec56f6a09af072709604
		Pattern pattern = Pattern.compile(regex);
		String returnString = null;
		HttpURLConnection  httpURLConnection = null;
		try {
			httpURLConnection = (HttpURLConnection) url.openConnection();
			httpURLConnection.connect();
			int responseCode = httpURLConnection.getResponseCode();
			if(responseCode == 200){
				System.out.println("成功");
				BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
				String temp;
			    while ((temp = reader.readLine()) != null) {
		        	 Matcher matcher = pattern.matcher(temp);
		 	        if(matcher.find()){
		 	        	returnString = matcher.group();
		 	        }
		       }
			    reader.close();
			}
	        httpURLConnection.disconnect();
		} catch (IOException e) {
			e.printStackTrace();
			if(httpURLConnection!=null){
				httpURLConnection.disconnect();
			}
		}finally{
			if(httpURLConnection!=null){
				httpURLConnection.disconnect();
			}
		}
		return returnString;
	}
}
运行截图(每次成功就代表你提取成功哦,并给你带来一个新的片片哈~~):


:-),我们来看看收集到的种子hash吧,^_^

:-),别看只是一串串的hash,用处可大哦,怎么使用呢请看:linux shell 让你批量上传种子到你云播空间