您所在的位置: 首页>>开发>>.Net>>asp.net>>

如何在ASP中实现PING

http://developer.51cto.com  2005-09-15 09:58  enet  eNet硅谷动力  我要评论(0)
  • 摘要:使用WSH调用系统的Ping命令,将Ping的结果重定向到一个文本文件中去,再把文本文件显示到网页中,具体做法见本文。
  • 标签:ASP
使用WSH调用系统的Ping命令,将Ping的结果重定向到一个文本文件中去,再把文本文件显示到网页中,具体做法如下:
首先, 建一个.BAT文件(例如:myPing.BAT:),这个文件要在ASP中调用,文件代码如下:
ping -a %1 > d:\INetPub\cgi-bin\%2.txt
(%1)是将来要ping的地址, (%2)是存储ping结果的文件. 以下是ASP的代码:
< %
Set FileSys = Server.CreateObject("Scripting.FileSystemObject")
FileName = FileSys.GetTempName
Set WShShell = Server.CreateObject("WScript.Shell")
IP = "xxx.xxx.xxx.xxx" ’你要ping的地址
RetCode = WShShell.Run("d:\Inetpub\cgi-bin\myPing.bat " & IP & " " & FileName, 1, True)
if RetCode = 0 Then
’没有错误
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(13) Then
Response.Write("
")
else
Response.Write(Mid(TextBuffer,i,1))
end if
Next
TextFile.Close
FileSys.DeleteFile "d:\Inetpub\cgi-bin\" & FileName & ".txt"
% >
专题:ASP.NET 2.0基础开发指南
微软的Ajax:Atlas(ASP.net AJAX)
ASP.NET开发教程
ASP实用开发教程
走向银光 —— 一步一步学Silverlight2
 
 验证码: (点击刷新验证码)   匿名发表
  • Visual Basic完全自学宝典

  • 作者:强锋科技,杨章伟
  • Visual Basic是用户最多的开发技术之一。本书由浅入深,循序渐进地教授读者如何使用Visual Basic开发应用系统,是Visual Basic..
Copyright©2005-2008 51CTO.COM 版权所有