如何每 500 毫秒执行一次 ping?

gee*_*225 17 ping cmd.exe

默认情况下,两次 ping 之间的时间延迟等于 1 秒。我需要将两次 ping 之间的延迟减少到 500 毫秒(0.5 秒)。有没有办法做到这一点?

n8t*_*8te 18

你可以用nping做到这一点(来自nmap的制造商)

  1. 首先下载并安装包含npingnmap包。
  2. 在命令提示符下将目录更改为 C:\Program Files (x86)\Nmap
  3. 现在运行以下命令:(nping --delay 500ms --count 0 <target ip address>
    --count 0选项将其设置为连续 ping)

....来自Nping 参考指南

Usage: nping [Probe mode] [Options] {target specification}
....
....
TIMING AND PERFORMANCE:
  Options which take <time> are in seconds, or append 'ms' (milliseconds),
  's' (seconds), 'm' (minutes), or 'h' (hours) to the value (e.g. 30m, 0.25h).
  --delay <time>                   : Adjust delay between probes.
  --rate  <rate>                   : Send num packets per second.
Run Code Online (Sandbox Code Playgroud)


Sim*_*onS 16

您可以在 中创建一个无限循环,在PowerShell那里发送 1 个 ping 并在发送后等待 500 毫秒。

while ($true) { Test-Connection ServerName -Count 1 ; Start-Sleep -MilliSeconds 500 }
Run Code Online (Sandbox Code Playgroud)

您也可以将其包装在一个函数中并放入您的 PowerShell 配置文件中以随时使用它

Function New-Ping {
    
    Param(
        [Parameter(Mandatory)]
        [string]$ComputerName,
        [Parameter(Mandatory)]
        [int]$Intervall
    )

    while ($true) { 
        Test-Connection $ComputerName -Count 1
        Start-Sleep -MilliSeconds $Intervall 
    }
}
Run Code Online (Sandbox Code Playgroud)

并从内部像这样使用它PowerShell

New-Ping ServerName 500
Run Code Online (Sandbox Code Playgroud)

你也可以cmd.exe像这样使用它:

C:\WINDOWS\system32>powershell new-ping SRV 500

Source        Destination     IPV4Address      IPV6Address                              Bytes    Time(ms)
------        -----------     -----------      -----------                              -----    --------
CP            SRV            10.0.0.226                                                32       0
CP            SRV            10.0.0.226                                                32       0
CP            SRV            10.0.0.226                                                32       0
Run Code Online (Sandbox Code Playgroud)

您可以通过按 CTRL + C 来结束无限循环

  • 我喜欢这个,因为它不需要安装单独的应用程序。我一直认为最好的答案至少应该提供一种方法来做到这一点,即使使用单独的程序更容易。 (2认同)

pbi*_*ies 16

在 Linux 上是可能的(最近最短时间更改为 200ms = 0.2):

ping -i 0.2 server.com
Run Code Online (Sandbox Code Playgroud)

根可以发出更短的时间:

ping -i 0.01 server.com
Run Code Online (Sandbox Code Playgroud)

  • 需要使用 0.5 才能达到 500ms (7认同)
  • 标签提到了 windows (cmd.exe) (3认同)
  • 这也适用于 macOS。 (3认同)

spi*_*hie 9

您无法在 Windows 命令行中更改每个 ping 请求之间的时间。你需要一个第三方工具,比如 fping 或 TruePing

另请参阅https://serverfault.com/questions/200468/how-can-i-set-a-short-timeout-with-the-ping-command


It *_* Me 8

  • 在 PowerShell 中
$cnt=0; while ($cnt -le 9) {$cnt++; Start-Sleep -MilliSeconds 500; Test-Connection 1.1.1.1 -Count 1}
Run Code Online (Sandbox Code Playgroud)
  • 使用别名的一种选择:
$cnt=0;while($cnt -le 9){$cnt++;Test-Connection 1.1.1.1  -Cou 1; sleep -M 500} 
Run Code Online (Sandbox Code Playgroud)

来自@wasif-hasan 的超级高尔夫版本评论建议:

0..9|%{test-Connection 1.1.1.1 -cou 1;sleep -m 500}
Run Code Online (Sandbox Code Playgroud)
  • 输出/结果:
Source        Destination     IPV4Address      IPV6Address                              Bytes    Time(ms) 
------        -----------     -----------      -----------                              -----    -------- 
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       18       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       20       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       15       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       17       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       15       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       19       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       16       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       16       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       18       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       19 
Run Code Online (Sandbox Code Playgroud)


  • 在蝙蝠/CMD 中:
@echo off 

:loop
pathping 127.1 -n -q 1 -p 500 >nul 2>nul 
ping 151.101.193.69 -n 1 -4 & goto=:loop
Run Code Online (Sandbox Code Playgroud)
  • 或者使用预定义的 ping/loop 限制:

@echo off & setlocal

:环形 路径 127.1 -n -q 1 -p 500 >nul 2>nul ping 1.1.1.1 -n 1 -4 & set /a "_cnt+=1+0" if %_cnt% leq 10 (goto:loop) else goto:eof


pathping从 Microsoft使用并随 Windows 提供

@echo off & setlocal

:loop pathping 127.1 -n -q 1 -p 500 >nul 2>nul ping 1.1.1.1 -n 1 -4 & set /a "_cnt+=1+0" if %_cnt% leq 10 (goto:loop)else goto:eof


C:\Users\ecker>where pathping
C:\Windows\System32\PATHPING.EXE
Run Code Online (Sandbox Code Playgroud)

Obs.:当指定-p 时,ping 将单独发送到每个中间跃点。当-w被指定时,多个坪可以并行发送。因此,可以选择小于等待周期 * 跳数的超时参数。


  • cmd/bat 的一些进一步阅读:

    [?] PathPing