我将创建一个小批处理文件,将我的 IP 地址直接复制到我的剪贴板。我试过:
@echo off
ipconfig | find "IPv4" | clip
pause
但给我:IPv4 地址。 . . . . . . . . . . : 192.168.xx.xx
。有没有办法只获取 192.168.xx.xx
?
最佳答案
for /f "tokens=2 delims=[]" %%a in ('ping -n 1 -4 ""') do echo %%a | clip
对本地机器执行
ping
命令(""
),使用ipv4只发送一个数据包(-n 1
) (-4
)ping
命令的输出在for/f
命令中处理ping
输出的第一行包含用方括号括起来的 ip 地址for/f
使用方括号作为分隔符对行进行标记化,并检索第二个标记
v v (delimiters) Pinging computername [x.x.x.x] with 32 bytes of data 1 2 3 (tokens)
关于batch-file - bat文件中只获取没有 "IPv4 Address. . . . . . . . . . . :"的IPv4地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43966069/