gpt4 book ai didi

windows - CMD Findstr 与 ping

转载 作者:可可西里 更新时间:2023-11-01 10:48:08 28 4
gpt4 key购买 nike

我正在编写一个批处理文件来 ping 一个网站,例如:

Pinging youtube.com [173.194.70.91] with 32 bytes of data:
Reply from 173.194.70.91: bytes=32 time=187ms TTL=44

Ping statistics for 173.194.70.91:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 187ms, Maximum = 187ms, Average = 187ms

我的程序必须只复制 IP 地址并将其保存到文本文件中。

因此它会 ping 到一个文本文件中

ping youtube.com >> file.txt

现在我使用 findstr 命令查找 IP 地址。如果我使用这个就好了:

ping youtube.com -n 1 >nul >>C:\Users\Adrian\Desktop\IP.txt
findstr /i "Reply from 173.194.70.93: bytes=32 time=188ms TTL=43 C:\IP.txt

IF %ERRORLEVEL% EQU 0 (
echo You are winning
) else (
echo You are losing
)
pause

现在它说我赢了,这是一件好事,但我的程序必须在不知情的情况下找到 IP 地址。所以 findstr 命令必须知道获取此处之间的 IP 地址...

"Reply from 173.194.70.91: bytes=32 time=187ms TTL=44"

因此它必须从该字符串中findstr IP。但我一直在谷歌搜索,但一无所获。

最佳答案

试试这个:

@echo off &setlocal 
for /f "tokens=2delims=[]" %%i in ('ping -n 1 youtube.com^|find "["') do set "ip=%%i"
echo.%ip%>>file.txt
endlocal

关于windows - CMD Findstr 与 ping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15484802/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com