Run the Ping command in ASP and return the result.

Source: Internet
Author: User
Run the Ping command in ASP and return the result.
In the Win2000 system, you can run the command through the Exec method of the Wscript. Shell object,
The simple code is as follows:
<% Response. Buffer = true %>
<%
Url = "www.topronet.com"

Set ob1_shell = CreateObject ("WScript. Shell ")
Set objCmd = obw.shell. Exec ("ping" & url)
StrPResult = objCmd. StdOut. Readall ()
Set objCmd = nothing: Set ob1_shell = nothing

StrStatus = "offline"
If InStr (strPResult, "TTL =")> 0 then strStatus = "online"

Response. write url & "status:" & strStatus
Response. write ". <br>" & replace (strPResult, vbCrLf, "<br> ")
Response. write "<br> Target = '_ blank'> http://blog.111cn.net/cqq </a>"
%>

WMI can be used in Windows XP or Windows. NET Server,
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 Each result in PingResult
If clng (result. StatusCode)> 0 then
Response. write "offline"
Else
Response. write "online"
End if
Next
%>
Of course, we can also compile the corresponding components or use some ready-made components to implement such functions,
I will not talk about it 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.