| ASP利用TCPIP.DNS组件实现域名IP查询方法详解
以下是代码片段: <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> <%Stime=Timer()%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>ASP域名IP查询</title> </head> <body> <form name="form1" method="post" action=""> <table width="528" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td height="25" align="right"> </td> <td align="center">ASP域名IP查询</td> <td> </td> </tr> <tr> <td width="96" height="25" align="right">域名:</td> <td width="288" align="center"><input type="text" name="URL" value="<%=Trim(Request.Form("URL"))%>" size="35"> <input type="hidden" name="Search" value="True"></td> <td width="144"><input type="submit" name="Submit" value="查询"></td> </tr> </table> </form> <table width="528" align="center" cellpadding="0" cellspacing="0" border="0"> <tr> <td width="64"> </td> <td width="464"> <%Search=Trim(Request.Form("Search")) If Search="True" Then URL=Trim(Request.Form("URL")) Set objWShell=CreateObject("WScript.Shell") Set objCmd=objWShell.Exec("ping "&url) StrPResult=objCmd.StdOut.Readall() Set objCmd=nothing Set objWShell=nothing On Error Resume Next IP=strCut(StrPResult,"[","]",2) If Err Then Err.Clear 'www.mintao.net IP="<b>此IP未知或域名不可用!</b>" End if Response.Write("<b>查询结果</b><br><br>您查询的域名:"&URL&"<br><br>IP地址为:"&IP&"<br>") 'Response.Write("<p>"&Replace(StrPResult,vbCrLf,"<br>"))'输出详细内容 EndTime=Timer() Response.Write("<br>查询时间共用:"&FormatNumber((EndTime-STime),3,-1)&"</b>秒") End if Function strCut(strContent,StartStr,EndStr,CutType) Dim strHtml,S1,S2 strHtml = strContent On Error Resume Next Select Case CutType Case 1 S1 = InStr(strHtml,StartStr) S2 = InStr(S1,strHtml,EndStr)+Len(EndStr) Case 2 S1 = InStr(strHtml,StartStr)+Len(StartStr) S2 = InStr(S1,strHtml,EndStr) End Select If Err Then strCute = "<b>没有找到需要的内容!</b>" Err.Clear Exit Function Else strCut = Mid(strHtml,S1,S2-S1) End If End Function%> </td> </tr> </table> </body> </html> |
但是运行后一直提示“WshShell.Exec (0x80070005) 拒绝访问”,网上搜了好一会儿,没有找到真正解决问题的办法,但是意外地让我找到了另个一个可以轻易实现这个功能的组件-“TCPIP.DNS组件”,只要两行代码即可,如下:
以下是代码片段: <%Set DNS=CreateObject("TCPIP.DNS") IP=DNS.GetIPByHost(www.mintao.net)%> | 希望以上关于ASP利用TCPIP.DNS组件实现域名IP查询方法详解对你有用。 |