今天得到消息,cn域名又可以注册了,因为前一阵子宫刑部大扫荡了一把,把个人注册的cn域名全部收回,所以现在很多好的cn域名都还存在.
我也是个域名控,但是总不能挨个挨个的去搜域名吧.这里提供一个Java程序.早上写的.
但是可能需要大家自己去物色判断域名是否被注册的URL。本站不提供.
注意 在运行本程序之前 请先 在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;
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 domainList = new ArrayList();
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();
}
}