1

複数のソースIPから1つのIPにpingを実行し、結果をファイルまたはHTMLページに書き込んで結果を取得する必要があります。4つのpingすべてから結果を取得して、TTLと、ドロップされた4つのpingの数とping時間を含める必要があります。

IPv6では、pingコマンドで-Sトリガーを使用してソースIPを指定できることは知っていますが、IPv4環境ではどのように指定しますか。

設定:

Windows2003サーバーR2標準x64。85個のIPv4アドレスを含む.txtファイルソースIPとして使用したい1個のターゲットIPv4アドレスが1台の中央サーバーから実行されます中央サーバーに管理者としてログインします

望ましい結果:ソースIPの結果ごとにグループ化された結果を表示するHTMLページ。これには、4つのping応答時間、TTL、送信されたパケットの合計、受信されたパケットの合計、および平均ping時間がミリ秒単位で含まれます。

少し複雑にしましょう。Windows2003サーバーR2標準x64の通常のインストールに含まれていない追加のソフトウェアをインストールできる環境にいません。.batファイルを書き込んでから何年も経ちましたが、.batファイルのメモリはまだ非常に弱いです。すべてのIPアドレスはIPv4です。これらすべてのサーバーのFQDNはありますが、IPを使用する必要があります(何らかの理由で)

目的のページを作成し、1つのシステムから複数のシステムにpingを実行するには、次の方法がありますが、残りの部分では、多数から1つのシステムにpingを実行する必要があるため、問題が発生しています。スクリプトで得られる結果は、適切にフォーマットされたhtmlページのみです。処理=完了とだけ表示されます。どこが間違っているのか…助けてください…</p>

ありがとうございました

---編集---pingをping.exeに変更し、%%iを引用符で囲みます-"%%i"これで結果が得られますが、期待していた形式ではありません。これは、32バイトの日付で127.0.0.1を固定する形式で結果を提供します。テキストファイルに出力しているように....から応答します。私がやりたいのは、表形式で表示することです。以下のコードに変更を加えました。

@echo off
echo ^<HTML^>^<HEAD^><TITLE^>SERVER PING INFO^</TITLE^>^</HEAD^> >>ping-results.html
echo ^<BODY GBCOLOR=#FFFFFF” TEXT=”#000000” LINK+#0000FF” VLINK=#800080”^> >>ping-results.html
echo ^<p align="center"^>^<table border="1" width="600"^> >>ping-results.html
echo ^<tr^>^<td^>^<B^>ping results^</td^> >> ping-results.html
for /F %%i in (c:\ping-results\serverIP.txt) do (
    echo Processing %%i...
    ping.exe "%%i" > "c:\ping-results\%%i.html" /format:htable.xsl
    echo ^<tr^>^<td^>%%i^</td^> >> ping-results.html
    echo ^<td^>^<a href="c:\ping-results\%%i.html"^>Results^</a^>^</td^> >> ping-results.html
    echo ^</tr^> >> ping-results.html
)
    echo ^<p align="center"^>^<b^>^<font size="+1" color="Red"^>^<BR^>Completed at >> ping-results.html time /T >> ping-results.html
echo - on >> ping-results.html
date /T >> ping-results.html
echo ^</font^>^</b^>^<BR^>^</p^> >> ping-results.html
echo.
echo DONE!!
4

1 に答える 1

2

htmlファイルを作成する前にpingコマンドを実行するのが最善ではないでしょうか。

このように(明らかに127.0.0.1をサーバーに変更します#)

@echo off
setlocal enabledelayedexpansion enableextensions
set count=0
for /f "delims=" %%a in ('ping -n 4 127.0.0.1') do (
    set /a count=!count!+1
    set pingrspn!count!=%%a
)
echo Response1: !pingrspn4!
echo Response2: !pingrspn5!
echo Response3: !pingrspn6!
echo Response4: !pingrspn7!

これで、「HTMLファイルの作成」スクリプトでvars:pingrspn4-pingrspn7を使用できます。

その場でhtmlをビルドするのはいい考えですが、私はそれが好きです。

ping行の/formatオプションに関する1つの質問ですが、pingには/ formatパラメーターがないことに気付きました。それで、/ formatオプションはリダイレクトシンボルから来ていますか?

[編集]それで、結果(server.html)ページをフォーマットするためにあなたのファイルを微調整しました(あなたはいくつかの欠落したhtmlコードを持っていました)

    :: setlocal options
        setlocal enabledelayedexpansion enableextensions
        set count=0
        for /f "delims=" %%a in ('ping -n 4 127.0.0.1') do (
            set /a count=!count!+1
            set pingrspn!count!=%%a
        )
        echo Response1: !pingrspn4!
        echo Response2: !pingrspn5!
        echo Response3: !pingrspn6!
        echo Response4: !pingrspn7!
:: write results file       
echo ^<HTML^>^<HEAD^><TITLE^>SERVER PING INFO^</TITLE^>^</HEAD^> >>ping-results.html 
echo ^<BODY GBCOLOR=#FFFFFF” TEXT=”#000000” LINK+#0000FF” VLINK=#800080”^> >>ping-results.html 
echo ^<p align="center"^>^<table border="1" width="600"^> >>ping-results.html 
echo ^<tr^>^<td^>^<B^>ping results^</td^> >> ping-results.html 
for /F %%i in (serverIP.txt) do (    
echo Processing %%i...     
 :: already ran the ping command, so rem it out
rem ping.exe "%%i" > "%%i.html" /format:htable.xsl   
:: write %%i.html
echo ^<HTML^>^<HEAD^><TITLE^>Individual PING^</TITLE^>^</HEAD^> >%%i.html 
echo ^<BODY GBCOLOR=#FFFFFF” TEXT=”#000000” LINK+#0000FF” VLINK=#800080”^> >>%%i.html 
echo ^<p align="center"^>^<table border="1" width="600"^> >>%%i.html 
echo ^<tr^>^<td^>^<B^>results^</td^> >> %%i.html  
        echo ^<tr^>^<td^>!pingrspn4! ^<^/td^>^<^/tr^> >> %%i.html 
        echo ^<tr^>^<td^>!pingrspn5! ^<^/td^>^<^/tr^>  >> %%i.html
        echo ^<tr^>^<td^>!pingrspn6! ^<^/td^>^<^/tr^>  >> %%i.html
        echo ^<tr^>^<td^>!pingrspn7! ^<^/td^>^<^/tr^>  >> %%i.html
        echo ^<^/body^> ^<^/table^> ^<^/html^> >> %%i.html
 echo ^<tr^>^<td^>%%i^</td^> >> ping-results.html     
 echo ^<td^>^<a href="%%i.html"^>Results^</a^>^</td^> >> ping-results.html     
 echo ^</tr^> >> ping-results.html )     
 echo ^<p align="center"^>^<b^>^<font size="+1" color="Red"^>^<BR^>Completed at >> ping-results.html 
 time /T >> ping-results.html 
 echo - on >> ping-results.html 
 date /T >> ping-results.html 
 echo ^</font^>^</b^>^<BR^>^</p^> >> ping-results.html 
 echo ^<^/body^> ^<^/table^> ^<^/html^> >>  ping-results.html 
 echo DONE!!
 ping-results.html
于 2012-04-20T20:24:56.497 に答える