如何将4个八位字节的IP地址转换为批处理* WINDOWS *

时间:2018-05-24 07:59:29

标签: windows batch-file cmd

首先,对不起我的英语。

嗨我正在寻找一个函数,变量或者其他东西,但是为了帮助我只获取ip的4个八位字节,我熟悉linux脚本但是我找不到一种方法来削减特定的ip。这是因为我必须将设备的信息(MAC,COMPUTERNAME,DATE)放在一个文本文件中,这样每次我这样做都会逐行写。

最后我想要这样的东西,我不在乎线上的顺序:

日期:24/05/2018 HOUR:8:56:20,62电脑名称:LZ1710172481 IP:10.138.53.150

基本上我只想要IP(4个八位字节)

非常感谢你。

这是脚本

@echo off
echo ===========================================
echo         = EQUIPMENT CONFIGURATION =
echo ===========================================
echo\
echo Today's date:% date%
echo.
echo Computer Name:% computername%
echo.
echo IP Address:
ipconfig | find / i "IPv4"
ipconfig | find / i "IPv4" >> \\ 10.138.50.215 \ test \ txtinfo.txt

echo.
echo MAC of the Team:
getmac
echo.
echo DATE:% date% TIME:% time% NAME OF THE COMPUTER:% computername% >> \\ 10.138.50.215 \ test \ txtinfo.txt

echo\
echo Press the "SPACE" key to close this window ...
pause> nul

1 个答案:

答案 0 :(得分:2)

for /f "tokens=2 delims=:" %%a in ('ipconfig ^|find "IPv4"') do set "ip=%%a"

如果您需要删除起始空间:

set "ip=%ip:~1%"

(注意:它是\\10.138.50.215\test\txtinfo.txt%date%%time%%computername%

以防万一,你也需要它:

for /f %%a in ('getmac') do set "mac=%%a"