仅获得没有“ IPv4地址”的IPv4地址。 。 。 。 。 。 。 。 。 。 。 :”在蝙蝠文件中 [英] Only get IPv4 address without the "IPv4 Address. . . . . . . . . . . :" in bat-file

查看:70
本文介绍了仅获得没有“ IPv4地址”的IPv4地址。 。 。 。 。 。 。 。 。 。 。 :”在蝙蝠文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将创建一个批处理文件,将我的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 a for /f command

      ping 输出包括括在方括号中的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 token

      
                               v       v          (delimiters)
          Pinging computername [x.x.x.x] with 32 bytes of data
          1                     2       3             (tokens)
      

      这篇关于仅获得没有“ IPv4地址”的IPv4地址。 。 。 。 。 。 。 。 。 。 。 :”在蝙蝠文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆