欢迎光临
我们一直在努力

域名查询-.NET教程,远程及网络应用

建站超值云服务器,限时71元/月

/// <summary>

/// 从“中国万网(www.net.cn)”实现域名查询功能

/// </summary>

/// <param name="domain">域名</param>

/// <param name="ext">后缀(cn|com|net|name|org|comcn|netcn|orgcn|govcn|info|biz|tv|cc)</param>

/// 以上依次代表:.cn|.com|.net|.name|.org|.com.cn|.net.cn|.org.cn|.gov.cn|.info|.biz|.tv|.cc

/// <returns></returns>

public static string whois( string domain, string ext )

{

#region 这部分可能会变化,取决于“中国万网”是否改变查询方式和显示查询结果的那个网页的内容

const string cnturlb = "http://panda.www.net.cn/cgi-bin/check.cgi?domain=";//http请求头部

const string cnturlm = "&ext="; //http请求中间部分(变量)

const string cntmark = "<tr bgcolor=\"#b9d9ff\">"; //需要的"中国万网"返回信息的开始特征

const string cnttableb = "<tr bgcolor=\"#993300\">"; //"中国万网"返回信息中的一个table的开始部分的特征

//已知"中国万网"查询结果的三种情况的特征

const string cntqn = "此域名不能注册";

const string cntreg = "已被注册的域名";

const string cntnotreg = "未被注册的域名";

#endregion

#region 这个部分选用

//以下用来替换"中国万网"返回信息中table的样式

const string cnttabler = "<tr><td>";

const string cnttablee = "</td></tr></table>";

const string cnttable = "<table align=center border=1 bordercolor=\"#ffffff\" cellpadding=\"1\" cellspacing=\"0\" bgcolor=\"#f7f7f7\"><tr>";

//自定义查询结果,用于页面显示

const string cntable = "恭喜你,这是一个";

const string cntnotconnect = "不能连接到服务器,请重试!";

#endregion

string strresult = string.empty;

try

{

#region 这里执行查询

//从"中国万网"查询域名

string strurl = cnturlb + domain + cnturlm + ext;

//建立请求

webrequest wrequest = webrequest.create( strurl );

// wrequest.proxy = new webproxy( "server", 8080 );//视情况设置代理

wrequest.timeout = 30000;

webresponse wresponse = wrequest.getresponse();//执行请求

stream responsestream = wresponse.getresponsestream();//读取万网返回结果

streamreader reader = new streamreader( responsestream, encoding.default );

string responsehtml = reader.readtoend();//将所有结果保存到字符串

wresponse.close();

#endregion

//取出万网查询结果

strresult = responsehtml.substring( responsehtml.indexof( cntmark ), responsehtml.indexof( cnttableb ) – responsehtml.indexof( cntmark ) );

#region 这个部分选用

//根据需要调整结果

strresult = cnttable + strresult + cnttabler;

if( responsehtml.indexof( cntqn ) > -1 )

{

strresult += cntqn + "!" + cnttablee;

}

else if( responsehtml.indexof( cntreg ) > -1 )

{

strresult += cntreg + "!" + cnttablee;

}

else if( responsehtml.indexof( cntnotreg ) > -1 )

{

strresult += cntable + cntnotreg + "!" + cnttablee;

}

else

{

strresult = responsehtml;

}

#endregion

}

catch( webexception )

{

strresult = cntnotconnect + "\n";

}

catch( uriformatexception err)

{

strresult = err.message;

}

return strresult;

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 域名查询-.NET教程,远程及网络应用
分享到: 更多 (0)

相关推荐

  • 暂无文章