在Windows系统中使用bat脚本获取IP和MAC地址的方法介绍

爱站 2024-12-06 27 0条评论
55Link友情链接交易平台
摘要: 我们可以使用Windows内置的ipconfig命令来获取IP地址。在bat脚本中,可以使用以下代码来获取IP地址:for/fdelims=:tokens=2%%iin(ipcon...

我们可以使用Windows内置的ipconfig命令来获取IP地址。在bat脚本中,可以使用以下代码来获取IP地址:

for /f "delims=: tokens=2" %%i in ('ipconfig ^| findstr /i "IPv4 Address"') do (set ip=%%iset ip=!ip:~1!)

要获取MAC地址,我们可以使用Windows的getmac命令。在bat脚本中,可以使用以下代码来获取MAC地址:

for /f "tokens=2 delims==" %%a in ('getmac /fo csv /nh') do (set mac=%%agoto done):done

通过以上两种方法,我们就可以在bat脚本中轻松地获取本机的IP和MAC地址,并在后续的脚本中使用这些信息。这种方法非常简单实用,适用于Windows系统下的各种自动化脚本。


求一个bat脚本能够获取到本机所有网卡的mac地址

WINDOWS系统,已知本地的IP,如何通过命令找到IP地址对应的MAC地址?

以下代码复制粘贴到记事本,另存为,编码选ANSI@echo offrem 根据本地的ip地址查找对应的mac地址/物理地址set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4title %#% +%$%%$%/%_% %z%set ip=192.168.1.2wmic nicconfig get IPAddress,MACAddress|findstr \%ip:.=\.%\echo;%#% +%$%%$%/%_% %z%pauseexit

BAT-批处理-怎样提取MAC地址并保存

楼主第2问我没看懂,下面给出代码,如果不是楼主想要的,就HI我吧。@echo offsetlocal enabledelayedexpansionfor /f tokens=1-2 delims=: %%i in (ipconfig /all ^|findstr Physical Address) do (set jieguo=%%jecho !jieguo!|find - && goto next ):nextset mac=!jieguo:-=!echo 123>> 我的MAC地址为:%mac: =%>>-GO网络知道团队--xie3331

文章版权及转载声明:

作者:爱站本文地址:http://www.awz.cc/post/8560.html发布于 2024-12-06
文章转载或复制请以超链接形式并注明出处爱网站

赞(0