How to get only the reply line of a ping test on Windows

后端 未结 7 1304
你的背包
你的背包 2021-02-04 12:01

Usually, when pinging a server IP address we have this in return:

Pinging  with 32 bytes of data:
Reply from  : bytes=32 time=151 TTL         


        
7条回答
  •  孤街浪徒
    2021-02-04 12:07

    You can accomplish this with powershell... here is the code you can add to a script

    $ping = new-object System.Net.NetworkInformation.Ping
    $reply = $ping.send('127.0.0.1')
    if ($reply.status -eq "Success"){
        [string]::Format("Reply from {0},time={1}",$reply.Address.ToString(),$reply.RoundtripTime)
        }else{
        $z = [system.net.dns]::gethostaddresses($hostname)[0].ipaddresstostring
        [string]::Format("FAIL,{0},{1}",$z,"***")
    }
    

    You can format the string in any format you want.

提交回复
热议问题