怎样使用ASP实现Ping

2016-01-29 18:16 49 1 收藏

怎样使用ASP实现Ping,怎样使用ASP实现Ping

【 tulaoshi.com - ASP 】

  This article presents a simple way to ping an address and get the results of the ping using ASP. The idea was supplied by Bart Silverstein.

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


ping -a %1 d:INetPubcgi-bin%2.txt
This will, if you can't tell, ping the address passed in as the first command line 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 call this from an 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:Inetpubcgi-binDoPing.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:InetPubcgi-bin" & FileName & ".txt", 1)
TextBuffer = TextFile.ReadAll

For i = 1 to Len(TextBuffer)

If Mid(TextBuffer,i,1) = chr(13) Then

Response.Write("<BR")

else

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

end if

Next

TextFile.Close

FileSys.DeleteFile "d:Inetpubcgi-bin" & FileName & ".txt"

%
Before you go hog wild and implement this code or use similar techniques on your site, there are a few things you should be wary of. From a secutiry standpoint, this is really dangerous, for any time you let someone run an application on your server there is always the potential that it will come back to haunt you. One suggestion to lessen the threat: make a separate folder with no script or execute priviledges, and have your DoPing.bat output its results to that folder.

I hope this article was informative an interesting. Happy Programming!
 

来源:http://www.tulaoshi.com/n/20160129/1505114.html

延伸阅读
标签: ASP
  最近做在做项目,涉及到文件上载的问题,找来资料研究了一下。当用户需要将文件传输到服务器上时,常用方法是使用FTP方式,用FTP的话虽然传输稳定,但安全性是个严重的问题,而且FTP服务器读用户库获取权限,这样对于用户使用来说还是不太方便。如果我们能把文件上载功能与Web集成,使用户仅用Web浏览器就能完成上载任务,这对于他...
标签: ASP
  大家经常探讨使用asp,而不使用其他组建能否实现文件的上传,从而开发出支持邮件附件的邮件系统,答案是可以的。请看: 以下是发送邮件的页面,邮件的帐号是员工号,假设是5位的数字,sendmail.asp当然是在合法登陆后才能够看到的 <html <head <meta http-equiv="Content-Type" content="text/html; charset...
标签: ASP
<script language="javascript" function openScript(url, width, height){ var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' ); } </script <form action="save.asp" method="POST" enctype="multipart/form-data" <tr <td width="17%" ...
标签: Web开发
Asp.Net 2.0 中实现了IButtonControl接口的控件都有一个PostBackUrl属性,可以进行跨页面提交,就是用的POST方法。那么在1.x中费了一番周折的POST提交就很简单了,只要把PostBackUrl设置为提交页,在那提交页用Request.Params[]就能拿到POST的表单参数了。还能用PreviousPage.FindControl去取前一页的控件。这里用Request和PreviousPage去...
标签: Web开发
通过xmlHttp和ASP的结合,我们可以轻松完成网页的异步调用。 代码如下: 1.新建Display.asp(这是前台显示页面) 注意xmlhttp.readyState的4个属性 1:LOADING;2:LOADED;3:INTERACTIVE;4:COMPLETED %@ Language=VBScript % HTML HEAD META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0" /HEAD script language="javascript" xmlhttp =...

经验教程

747

收藏

53
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部