最近突然发现双拼域名越来越少,价格也在不断上涨。想注册一个有趣的双拼域名玩玩,于是动手写了一个暴力查询双拼域名的工具。
思路比较简单,首先找到域名查询的接口,这些接口一般都会做策略防止暴力查询,这边我使用了2个接口作为容错。
aaw8:http://www.aaw8.com/Api/DomainApi.aspx?domain=chenrensong.com
{
StateID: 0,
DomainName: null,
Result: null
}
返回第一个参数为域名查询状态: 0 表示查询接口出错 1 表示网络异常 200 表示接口返回成功 210 表示域名可以注册 211 表示域名已经注册 212 表示域名参数传输错误 213 查询超时
万网:http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=chenrensong.com
<?xml version="1.0" encoding="gb2312"?>
<property>
<returncode>200</returncode>
<key>datiancun.com</key>
<original>211 : Domain name is not available</original>
</property>
返回 XML 结果说明:
returncode=200
表示接口返回成功
key=***.com
表示当前check的域名
original=210 : Domain name is available 表示域名可以注册
original=211 : Domain name is not available 表示域名已经注册
original=212 : Domain name is invalid 表示域名参数传输错误
original=213 : Time out 查询超时
有了接口之后一切都比较好办了,这时候需要一个拼音的单词表
private static string CONST = @"a,ai,an,ang,ao,ba,bai,ban,bang,bao,bei,ben,beng,bi,bian,biao,bie,bin,bing,bo,bu,ca,cai,can,cang,cao,ce,cen,ceng,cha,chai,chan,chang,chao,che,chen,cheng,chi,chong,chou,chu,chuan,chuang,chui,chun,chuo,ci,cong,cou,cu,cuan,cui,cun,cuo,da,dai,dan,dang,dao,de,deng,di,dia,dian,diao,die,ding,diu,dong,dou,du,duan,dui,dun,duo,e,en,er,fa,fan,fang,fei,fen,feng,fo,fou,fu,ga,gai,gan,gang,gao,ge,gei,gen,geng,gong,gou,gu,gua,guai,guan,guang,gui,gun,guo,ha,hai,han,hang,hao,he,hei,hen,heng,hong,hou,hu,hua,huai,huan,huang,hui,hun,huo,ji,jia,jian,jiang,jiao,jie,jin,jing,jiong,jiu,ju,juan,jue,ka,kai,kan,kang,kao,ke,ken,keng,kong,kou,ku,kua,kuai,kuan,kuang,kui,kun,kuo,la,lai,lan,lang,lao,le,lei,leng,li,lia,lian,liang,liao,lie,lin,ling,liu,lo,long,lou,lu,luan,lun,luo,lv,ma,mai,man,mang,mao,me,mei,men,meng,mi,mian,miao,mie,min,ming,miu,mo,mou,mu,na,nai,nan,nang,nao,ne,nei,nen,neng,ni,nian,niang,niao,nie,nin,ning,niu,nong,nou,nu,nuan,nuo,nv,o,ou,pa,pai,pan,pang,pao,pei,pen,peng,pi,pian,piao,pie,pin,ping,po,pou,pu,qi,qia,qian,qiang,qiao,qie,qin,qing,qiong,qiu,qu,quan,que,qun,ran,rang,rao,re,ren,reng,ri,rong,rou,ru,ruan,rui,run,ruo,sa,sai,san,sang,sao,se,sen,seng,sha,shai,shan,shang,shao,she,shen,sheng,shi,shou,shu,shua,shuai,shuan,shuang,shui,shun,shuo,si,song,sou,su,suan,sui,sun,suo,ta,tai,tan,tang,tao,te,teng,ti,tian,tiao,tie,ting,tong,tou,tu,tuan,tui,tun,tuo,wa,wai,wan,wang,wei,wen,weng,wo,wu,xi,xia,xian,xiang,xiao,xie,xin,xing,xiong,xiu,xu,xuan,xue,xun,ya,yan,yang,yao,ye,yi,yin,ying,yo,yong,you,yu,yuan,yue,yun,za,zai,zan,zang,zao,ze,zei,zen,zeng,zha,zhai,zhan,zhang,zhao,zhe,zhen,zheng,zhi,zhong,zhou,zhu,zhua,zhuai,zhuan,zhuang,zhui,zhun,zhuo,zi,zong,zou,zu,zuan,zui,zun,zuo";
通过遍历单词表来查询双拼域名,再请求相应的服务即可
HttpClient client = new HttpClient();
var response = await client.GetAsync(url);
var result = await response.Content.ReadAsStringAsync();
result = resolve(result);
需要说明的是aaw8的接口比较挫,返回的是html 包装的json…
需要正则把body里面的部分给截取出来
private static string ReadHtmlToEditHtml(string htmlContent1)
{
Regex reg = new Regex("(?is)<body[^>]*>(?<body>.*?)</body>");
string bodyHtml = "";
bodyHtml = reg.Match(htmlContent1).Groups["body"].Value;
return bodyHtml;
}
剩下来的就是写个返回数据解析了,为了防止查询过的域名再查询一遍浪费时间,我简单做了下本地cache,完整的代码如下
private async Task<ResultModel> FindDomain(string entity)
{
String filePath = "D:\\cache\\" + md5(url) + "_com.txt";
string fileContents = "";
if (File.Exists(filePath))
{
fileContents = File.ReadAllText(filePath);
}
else
{
HttpClient client = new HttpClient()
var response = await client.GetAsync(url);
var result = await response.Content.ReadAsStringAsync();
result = resolve(result);
fileContents = result;
bool flag = true;
try
{
JsonConvert.DeserializeObject(fileContents);
flag = true;
File.WriteAllText(filePath, fileContents);
}
catch (Exception ex)
{
flag = false;
}
}
var obj = (ResultModel)Newtonsoft.Json.JsonConvert.DeserializeObject(fileContents, typeof(ResultModel));
return obj;
}