How to use ASP to implement Ping

Source: Internet
Author: User
Tags command line implement
This is article presents a simple way to ping a, and get the results of the ping using ASP. The idea is supplied by Bart Silverstein.

A. BAT file needs to is created that is run from the Active Server Page. Let ' s call this file Doping.bat. It'll contain only one statement, which'll ping a passed in IP address. Here's the code for Doping.bat:


Ping-a%1 > D:\INetPub\cgi-bin\%2.txt
This would, if you can's tell, ping the address passed in as the the "the" "the" "Argument" (% 1), and redirect the results To a text file named hy the second command line argument (% 2). Now, let's look how we would the call this from a ASP file:


<%

Set Filesys = Server.CreateObject ("Scripting.FileSystemObject")
FileName = Filesys.gettempname

Set WshShell = Server.CreateObject ("Wscript.Shell")

IP = "204.123.54.1" ' or whatever you want to ping
RetCode = Wshshell.run ("D:\Inetpub\cgi-bin\DoPing.bat" & IP & "" & FileName, 1, True)

If RetCode = 0 Then

' There were no errors

Else

Response.Redirect "Pingerrors.htm"

End If


Set textfile = Filesys.opentextfile ("d:\InetPub\cgi-bin\" & FileName & ". txt", 1)
TextBuffer = Textfile.readall

For i = 1 to Len (textbuffer)

If Mid (textbuffer,i,1) = Chr Then

Response.Write ("<BR>")

Else

Response.Write (Mid (textbuffer,i,1))

End If

Next

Textfile.close

Filesys.deletefile "d:\Inetpub\cgi-bin\" & FileName & ". txt"

%>
Before Hog Wild and implement this code or use similar techniques on your site, there are a few things you should b E wary of. From a secutiry standpoint, the This is really dangerous, for no time you let someone run a application on your server there is always the potential that it'll come back to haunt for you. One suggestion to lessen the Threat:make a separate folder with no script or execute priviledges, and have your doping.ba T output its results to that folder.

I hope this article is informative an interesting. Happy programming!


Related Article

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.