【问题标题】:batch file - getting ip from ping command批处理文件 - 从 ping 命令获取 ip
【发布时间】:2012-02-28 14:47:35
【问题描述】:

我有这个命令。

ping -n 1 piratelufi.com | find /i "reply from"

我想在 ping 响应中获取 ip。我想过使用 %var:~0,10% 但我不知道如何将输出重定向到 echo。

我什至尝试使用管道

ping -n 1 piratelufi.com | find /i "reply from" | echo %1 

但是 %1 变量不代表前两个命令的输出。我什至尝试使用 &1 但我失败了。回显前两个命令的输出所需的“变量”是什么?

【问题讨论】:

    标签: file redirect batch-file ping


    【解决方案1】:

    查看FOR 命令真的很酷:

    FOR /f "tokens=1,3 delims=: " %%A IN ('ping -n 1 piratelufi.com') DO IF %%A==Reply ECHO IP IS %%B
    

    【讨论】:

      【解决方案2】:

      尝试以下方法:

      for /f "tokens=2 delims=[]" %f in ('ping -4 -n 1 piratelufi.com ^|find /i "pinging"') do echo IP=%f
      

      【讨论】:

        猜你喜欢
        • 2022-10-21
        • 1970-01-01
        • 2015-06-06
        • 2018-08-06
        • 1970-01-01
        • 2013-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多