检查域名是否可用

1.使用万网给出的API接口

http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=baidu.com
返回的结果为



200
baidu.com
211 : Domain name is not available


2.使用java接收URL返回的数据,如果返回的数据内有“Domain name is available”,则这个域名是可以用的

urlsite的格式为“域名+.+域名后缀”

public static void getAvaiableURL(String urlsite){

		try{
			String urlStr = "http://panda.www.net.cn/cgi-bin/check.cgi?area_domain="+urlsite;  
			URL url = new URL(urlStr);  
			URLConnection URLconnection = url.openConnection(); 
			HttpURLConnection httpConnection = null;
			httpConnection = (HttpURLConnection)URLconnection;
			
			InputStream urlStream = httpConnection.getInputStream();  
			BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlStream));  
			String sCurrentLine = "";  
			String sTotalString = "";  
			while ((sCurrentLine = bufferedReader.readLine()) != null) {  
			    sTotalString += sCurrentLine;  
			}  
			if (sTotalString.contains("Domain name is available")) {  
				System.out.println("Available--"+urlsite);
			} else {  
			}
		}catch(IOException e){
			getAvaiableURL(urlsite);
		}
	}


 
  

你可能感兴趣的:(检查域名是否可用)