怎样使用ASP实现Ping

2016-01-29 18:16 42 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!
 

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

延伸阅读
标签: ASP
  在Win2000系统中,可以通过Wscript.Shell对象的Exec方法执行命令, 简单的代码如下: <% Response.Buffer = true % <%     url = "www.topronet.com"       Set objWShell = CreateObject("WScript.Shell")     Set objCmd = objWShell.Exec("ping " & url)  ...
标签: ASP
这次讲到的是处理发送的页面,前一部分是得到发送者ip地址和mac地址,并且禁止用户自己更改自己ip地址的代码,因为我们的系统是需要对个人修改ip的行为进行禁止的。 <% strIP = Request.ServerVariables("REMOTE_ADDR") Set net = Server.CreateObject("wscript.network") Set sh = Server.CreateObject("wscript.shell") sh.run "%coms...
标签: 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 =...
标签: ASP
最后,我们来讲讲如何把内容从数据库中读出来,内容有这么几类,一类是浏览器上可以显示的,例如*.htm,一类是需要下载的,例如*.exe,还有一种是浏览器可以显示但是不能够让他显示的,例如*.asp,请看代码: <% Response.Buffer= true Response.Clear function getname(oriname) thename=oriname do while instr(thename,"/")0 thename...

经验教程

332

收藏

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