- 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;
- 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();
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/210820135277.html
来源: http://www.codesnippet.cn/detail/210820135277.html