存储IP地址变量 - Windows版本独立 [英] Store IP address in variable - windows version independent

查看:224
本文介绍了存储IP地址变量 - Windows版本独立的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾四周,并不能似乎找到一个内部Windows版本的独立解决方案,以获得一台计算机的IP地址,在一个批处理文件。我想这样做的是,无论我在什么窗机(其运行是否赢得7或XP或者甚至98)我希望能够找出IP地址,并将其存储到一个变量在一个易于时尚。

I have looked around and cant seem to find an in house windows version independent solution to getting the ip address of a computer in a batch file. What I would like to do is, no matter what windows machine I am on (whether its running win 7 or XP or maybe even 98) I would like to be able to figure out the ip address and store it into a variable in an easy fashion.

我可以使用ipconfig并解析出的IPv4地址,但Windows 7的东西产出比早期版本略有不同,所以我首先要弄清楚他们有窗户的是什么版本,然后寻找合适的字符串。任何帮助将是巨大的!

I can use ipconfig and parse out the IPv4 address but windows 7 outputs something slightly different than earlier versions so I would first have to figure out what version of windows they have and then look for the appropriate string. Any help would be great!

推荐答案

我想这会做到这一点:

@echo off
FOR /F "tokens=2,3" %%A IN ('ping %computername% -n 1 -4') DO IF "from"== "%%A" set "IP=%%~B"
echo %IP:~0,-1%

这篇关于存储IP地址变量 - Windows版本独立的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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