当前位置:   article > 正文

批处理文件获取本机mac地址与ip地址_批处理文件显示本机ip和mac

批处理文件显示本机ip和mac

桌面新建txt文件,将代码复制后另存为bat文件,另存为时编码改为ANSI:

  1. @echo off & setlocal enabledelayedexpansion
  2. echo =-----------------------------------------=
  3. echo = 本BAT只列出一个有线和一个无线的IP信息 =
  4. echo = 读取信息请耐心等待 =
  5. echo =-----------------------------------------=
  6. echo.
  7. for /f "tokens=1 delims=[]" %%i in ('%SystemRoot%\system32\nbtstat -S^|find /n "以太网:"') do (
  8. nbtstat -S | more +%%i >$
  9. set /p Str=<$
  10. del $
  11. for /f "tokens=2 delims=[]" %%i in ('echo "!Str!"') do set LIP=%%i
  12. )
  13. for /f "tokens=1 delims=[]" %%i in ('%SystemRoot%\system32\nbtstat -S^|find /n "WLAN:"') do (
  14. nbtstat -S | more +%%i >$
  15. set /p Str=<$
  16. del $
  17. for /f "tokens=2 delims=[]" %%i in ('echo "!Str!"') do set WIP=%%i
  18. )
  19. for /f "tokens=16" %%i in ('ipconfig /all ^| find /i "IPv4 地址"') do set ip=%%i ?
  20. echo =================================================== >%tmp%\ip-mac.txt
  21. echo 当前时间:%DATE% >>%tmp%\ip-mac.txt
  22. echo =================================================== >>%tmp%\ip-mac.txt
  23. echo 本机用户名为:%COMPUTERNAME% >>%tmp%\ip-mac.txt
  24. echo 本机有线IP为:%LIP% >>%tmp%\ip-mac.txt
  25. echo 本机无线IP为:%WIP% >>%tmp%\ip-mac.txt
  26. ::echo 本机首选IP为:%ip% >>%tmp%\ip-mac.txt
  27. echo 本机物理地址: >>%tmp%\ip-mac.txt
  28. echo ===================================================
  29. for /f "tokens=1,3 delims=," %%i in ('getmac /v /nh /fo:csv ^| findstr
  30. "..-..-..-..-..-.."') do (
  31. echo %%i %%j >>%tmp%\ip-mac.txt
  32. )
  33. echo =================================================== >>%tmp%\ip-mac.txt
  34. ipconfig | findstr /i "以太网 无线 IPv4">>%tmp%\ip-mac.txt
  35. Start %tmp%\ip-mac.txt

转自:批处理获取本机IP地址及MAC地址,输出到文件 - 简书 (jianshu.com)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/算法编织者2/article/detail/61776
推荐阅读
相关标签
  

闽ICP备14008679号