Here is a short code sample that should get you started. If you are using Windows 2000 or better, you can use Exec from WScript.Shell:
<% Response.Buffer = true %> <% url = "www.espn.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 & " is " & strStatus response.write ".<br>" & replace(strPResult,vbCrLf,"<br>") %> |
If you are running Windows XP or Windows.NET Server, you can use WMI's new Win32_PingStatus namespace, e.g.:
<% url = "www.espn.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 & " is " For Each result in PingResult if clng(result.StatusCode)>0 then response.write "offline" else response.write "online" end if Next %> |
If for some reason you can't use the shell or WMI, there are many components that can handle the task.
ASPPing DesPing DSPing Pro DynuDNS kutil NETDLL (currently the download link is 404)
w3 Utils