WEB开发网
开发学院软件开发Java Java写批量域名注册查询程序 阅读

Java写批量域名注册查询程序

 2012-05-31 13:17:59 来源:WEB开发网   
核心提示:注意 在运行本程序之前 请先 在d盘下面创建domains文件夹package com.cha;import java.io.BufferedReader;import java.io.DataOutputStream;import java.io.File;import java.io.FileOutputStrea

注意 在运行本程序之前 请先 在d盘下面创建domains文件夹

package com.cha;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.security.AllPermission;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 *
* <p>Title: </p>
* <p>desc:
* <p>Copyright: Copyright(c)Gb 2012</p>
* @author 三少
* @time 上午11:57:56
* @version 1.0
* @website http://www.ij2ee.com/49694.html
* @since
 */
public class Cha {
	final char[] String = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
			'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
			'x', 'y', 'z', };
	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {

		final Cha c = new Cha();
		//开启查询线程
		new Thread(new Runnable() {

			@Override
			public void run() {
				c.aillTaskList();
			}
		}).start();

		//开启写文件线程
		new Thread(new Runnable() {

			@Override
			public void run() {
				try {
					while(true){
						c.saveFile();

					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}).start();
	}

	private void aillTaskList() {
		new Thread(new Runnable() {

			@Override
			public void run() {
				//3个for循环 表示三位字母的。
				for (int i = 0; i < String.length; i++) {
					for (int j = 0; j < String.length; j++) {
						for (int k = 0; k < String.length; k++) {
							String domain = String[i] + "" + String[j]
									+ String[k];
							try {
								System.out.println(domain);
								chaIt(domain);

							} catch (Exception e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
						}
					}
				}
			}
		}).start();

	}

	List<String> domainList = new ArrayList<String>();
	StringBuffer sb = new StringBuffer();

	/**
	 *
	 * @param domain 域名内容 比如 www.ij2ee.com
	 * @throws Exception
	 */
	private void chaIt(String domain) throws Exception {
		//这种查是否被注册的url 大家自己找 比如
		String url = "http://www.xxxx.com/cgi-bin/domainquery.cgi?flag=1&domainname="+ domain ;
		URL u = new URL(url);
		String res = readInputStream(u.openStream(), "UTF-8");
		if (res.endsWith("1")) {
			domainList.add(res);
		}

	}

	public int delay = 1000;

	private void saveFile() throws Exception {
		//减少本机压力 睡眠一会儿
		Thread.sleep(delay);
		System.out.println("domainList.size = "+domainList.size());
		if (domainList.size() >= 10) {
			for (String d : domainList) {
				sb.append(d).append(",");
			}
			saveFile(sb.toString());
			// sb =new StringBuffer();
			domainList.clear();
			delay = 1000;
		} else {
			delay = 5000;
		}
	}

	//默认保存在domains下。
	void saveFile(String data) throws Exception {
		String filePath = "D:\\domains\\" + UUID.randomUUID().toString()
				+ ".txt";
		File f = new File(filePath);
		if (!f.exists()) {
			f.createNewFile();
		}
		FileOutputStream fOut = new FileOutputStream(filePath);
		DataOutputStream out = new DataOutputStream(fOut);
		out.writeUTF(data);
		out.flush();
		out.close();

	}

	public static String readInputStream(InputStream is, String encode)
			throws IOException {
		if (encode == null) {
			encode = "UTF-8";
		}
		BufferedReader in = new BufferedReader(
				new InputStreamReader(is, encode));
		StringBuffer buffer = new StringBuffer();
		String line;
		int isFrist = 0;
		while ((line = in.readLine()) != null) {
			// System.out.println(line);
			buffer.append(line);
		}
		is.close();
		return buffer.toString();
	}
}

Tags:Java 批量 域名注册

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接