WSH を使用してシステムの Ping コマンドを呼び出し、Ping 結果をテキスト ファイルにリダイレクトし、そのテキスト ファイルを Web ページに表示します。具体的な方法は次のとおりです。
まず、.BAT ファイル (例: myPing.BAT:) を作成します。このファイルのコードは次のとおりです。
ping -a %1 > d:/INetPub/cgi-bin/%2.txt
(%1) は今後 ping を実行するアドレス、(%2) は ping 結果を保存するファイルです。 ASP のコードは次のとおりです。
<%
FileSys = Server.CreateObject(Scripting.FileSystemObject) を設定します。
ファイル名 = FileSys.GetTempName
WShShell = Server.CreateObject(WScript.Shell) を設定します。
IP = xxx.xxx.xxx.xxx 'pingを送信するアドレス
RetCode = WShShell.Run(d:/Inetpub/cgi-bin/myPing.bat & IP & & ファイル名, 1, True)
RetCode = 0 の場合
'エラーはありません
それ以外
Response.Redirect PingErrors.htm
終了する場合
Set TextFile = FileSys.OpenTextFile(d:/InetPub/cgi-bin/ & FileName & .txt, 1)
TextBuffer = TextFile.ReadAll
i = 1 の場合、Len(TextBuffer)
Mid(TextBuffer,i,1) = chr(13) の場合
応答.書き込み(
)
それ以外
Response.Write(Mid(TextBuffer,i,1))
終了する場合
次
TextFile.Close
FileSys.DeleteFile d:/Inetpub/cgi-bin/ & ファイル名 & .txt
%>