Board logo

标题: [文本处理] [分享]批处理一键获取内网MAC地址 内网IP地址 [打印本页]

作者: q120072949    时间: 2011-1-26 18:23     标题: [分享]批处理一键获取内网MAC地址 内网IP地址

感谢BATHOME版主和各位高手
2个传送门:
批处理如何获取本地连接的MAC地址?
http://www.bathome.net/thread-10864-1-1.html
批处理为何获取不到正确的本地连接IP?
http://www.bathome.net/viewthrea ... p;extra=&page=1
第一个是获取内网MAC地址,第二个获取内网IP地址
现在代码综合如下:
  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "delims=" %%a in ('ipconfig/all') do call:a "%%a"
  3. for /f "tokens=2 delims=:" %%a in ('ipconfig /all^|find "Physical Address"') do set MAC=%%a
  4. ipconfig /all>"%temp%\ipList.txt"
  5. for /f "tokens=1 delims=:" %%a in ('findstr /n "Ethernet adapter" "%temp%\ipList.txt"') do (
  6.     set SkipRow=%%a
  7.     goto :DoSkip
  8. )
  9. :DoSkip
  10. for /f "usebackq skip=%SkipRow% tokens=1,15" %%a in ("%temp%\ipList.txt") do (
  11.     if "%%a" equ "IP" (
  12.         set IP=%%b
  13.         goto :ShowResult
  14.     )
  15. )
  16. :ShowResult
  17. echo;%ip%:%e%
  18. pause
  19. :a
  20. set "a=%~1"
  21. if defined a if not "!a:~0,1!"==" " set "b=!a:~0,1!"
  22. for /f "tokens=1,2* delims=:. " %%b in ("%~1") do if /i "%%b %%c"=="Physical Address" set %b%=%%d
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2