ping command in ASP, and return result

Source: Internet
Author: User
Executes the ping command in ASP and returns the result


In a Win2000 system, commands can be executed by the Exec method of the Wscript.Shell object,

The simple code is as follows:

<% Response.Buffer = True%>
<%
url = "Www.topronet.com"

Set Objwshell = CreateObject ("Wscript.Shell")
Set objcmd = objwshell.exec ("ping" & URL)
Strpresult = ObjCmd.StdOut.Readall ()
Set objcmd = Nothing:set Objwshell = Nothing

strstatus = "Offline"
If InStr (Strpresult, "ttl=") >0 then strstatus = "Online"

Response.Write URL & "status is:" & strstatus
Response.Write ".<br>" & Replace (Strpresult,vbcrlf, "<br>")
Response.Write "<br>
target= ' _blank ' >http://blog.csdn.net/cqq</a> '
%>



In XP or Windows.NET server systems, WMI can be used to implement the

The code is as follows:

<%
url = "Www.topronet.com"

WMI = "Winmgmts:{impersonationlevel=impersonate}"

Wqlquery = "Select StatusCode from Win32_PingStatus WHERE Address" & _
"= '" & URL & "'"

Set pingresult = GetObject (WMI). ExecQuery (Wqlquery, "WQL", 48)


Response.Write URL & "Status"
For Pingresult
If CLng (result. StatusCode) >0 Then
Response.Write "Offline"
Else
Response.Write "Online"
End If
Next
%>


Of course, we can also write the appropriate components ourselves or use some ready-made components to achieve this function,

There's not much to say here.





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.