仅获得没有“ IPv4地址”的IPv4地址。 。 。 。 。 。 。 。 。 。 。 :”在蝙蝠文件中 [英] Only get IPv4 address without the "IPv4 Address. . . . . . . . . . . :" in bat-file
问题描述
我将创建一个批处理文件,将我的IP地址直接复制到剪贴板。我尝试过:
I will create a little batch file to copy my IP address directly to my clipboard. I have tried:
@echo off
ipconfig | find "IPv4" | clip
pause
但是给我: IPv4地址。 。 。 。 。 。 。 。 。 。 。 :192.168.xx.xx
。有没有办法只得到 192.168.xx.xx
?
But gives me: IPv4 Address. . . . . . . . . . . : 192.168.xx.xx
. Is there a way to only get 192.168.xx.xx
?
推荐答案
for /f "tokens=2 delims=[]" %%a in ('ping -n 1 -4 ""') do echo %%a | clip
-
执行
ping
命令到本地计算机(-n 1
)使用ipv4(-4
)Execute a
ping
command to local machine (""
), sending only one packet (-n 1
) using ipv4 (-4
)ping的输出
命令在/ f 命令的内部
The output of the
ping
command is processed inside afor /f
commandping
输出包括括在方括号中的IP地址The first line in the
ping
output includes the ip address enclosed in square brackets用于/的
f
使用方括号作为定界符对行进行标记化,并检索第二个标记The
for /f
tokenizes the line using the square brackets as delimiters, and retrieve the second tokenv v (delimiters) Pinging computername [x.x.x.x] with 32 bytes of data 1 2 3 (tokens)
这篇关于仅获得没有“ IPv4地址”的IPv4地址。 。 。 。 。 。 。 。 。 。 。 :”在蝙蝠文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!