Tuesday, July 14, 2009

How can I ping an ip address remotely by ASP

Hey, Programming Guy! How can I ping an ip address remotely by ASP from an IIS server?
- Jennifer

 


Hi, Jennifer, we can use WScript.Shell to run a shell command to achieve this. Suppose the IIS have the access right for ping.exe which is located at system32 path inside windows. You can use the following VBScript by setting the id as a parameter to the destinated computer:


<%
url = Trim(Request("ip"))
if url<>"" Then
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 strStatus
End If
%>

2 comments:

nivetha said...

Thanks for the information about the ip address.I know my ip address from the site www.ip-details.comFrom Yours I learned the different information.Thank U.

Cloudgen said...

nivetha, you are welcome.