Board logo

标题: [网络工具] 批处理应用WMIC滤取网卡配置及状态简明信息 [打印本页]

作者: neorobin    时间: 2010-5-16 00:11     标题: 批处理应用WMIC滤取网卡配置及状态简明信息

参考: WMI 类 Win32_NetworkAdapter
http://msdn.microsoft.com/en-us/library/aa394216(VS.85).aspx
代码获取与 ipconfig /all 相类似的信息
  1. @echo off&setlocal enableDelayedExpansion
  2. call :getEnum %~s0 AdapterType
  3. call :getEnum %~s0 NetConnectionStatus
  4. call :getEnum %~s0 ConfigManagerErrorCode
  5. >NIC.TXT 2>nul (
  6.   echo 计算机名: %computername%&echo.&echo IP 可用网卡:
  7.   for /f "tokens=1,2 delims==" %%a in ('wmic nicconfig where "ipenabled='true'" get /value') do (
  8.     set "%%a=%%b"
  9.     if /i "%%a"=="Index" (
  10.       set /a "%%a=%%b"
  11.       for /f "tokens=1,2 delims==" %%x in ('wmic nic where "index=!index!" get /value') do (
  12.         set "%%x=%%y"
  13.         if /i "%%x"=="NetConnectionStatus" for %%z in (%%y) do set "%%x=!%%x%%z!"
  14.         if /i "%%x"=="ConfigManagerErrorCode" for %%z in (%%y) do set "%%x=!%%x%%z!"
  15.       )
  16.     )
  17.     if /i "%%a"=="WINSSecondaryServer" (
  18.       call :getIP IPAddress& call :getIP IPSubnet& call :getIP DefaultIPGateway& call :getIP DNSServerSearchOrder
  19.       echo.
  20.       echo =====================================================
  21.       echo.&echo !NetConnectionID!&echo.
  22.       echo AdapterType . . . . . . . . : !AdapterType!
  23.       echo DNSDomainSuffixSearchOrder. : !DNSDomainSuffixSearchOrder!
  24.       echo Name. . . . . . . . . . . . : !Name!
  25.       echo NetConnectionStatus . . . . : !NetConnectionStatus!
  26.       echo ConfigManagerErrorCode. . . : !ConfigManagerErrorCode!
  27.       echo MACAddress. . . . . . . . . : !MACAddress!
  28.       echo DHCPEnabled . . . . . . . . : !DHCPEnabled!
  29.       echo IPAddress . . . . . . . . . : !IPAddress!
  30.       echo IPSubnet. . . . . . . . . . : !IPSubnet!
  31.       echo DefaultIPGateway. . . . . . : !DefaultIPGateway!
  32.       echo DHCPServer. . . . . . . . . : !DHCPServer!
  33.       set "dnsPrintHead=DNSServerSearchOrder. . . ."
  34.       for %%d in (!DNSServerSearchOrder!) do (
  35.                    echo !dnsPrintHead! : %%d
  36.         set "dnsPrintHead=                           "
  37.       )
  38.       echo DHCPLeaseObtained . . . . . : !DHCPLeaseObtained!
  39.       echo DHCPLeaseExpires. . . . . . : !DHCPLeaseExpires!
  40.     )
  41.   )
  42.   echo.
  43.   echo 非正常工作设备:
  44.   for /f "tokens=1,2 delims==" %%a in ('wmic nic where "ConfigManagerErrorCode>0" get /value') do (
  45.     set "%%a=%%b"
  46.     if /i "%%a"=="NetConnectionStatus" for %%z in (%%b) do set "%%a=!%%a%%z!"
  47.     if /i "%%a"=="ConfigManagerErrorCode" for %%z in (%%b) do set "%%a=!%%a%%z!"
  48.     if /i "%%a"=="TimeOfLastReset" (
  49.       echo.
  50.       echo =====================================================
  51.       echo.&echo !NetConnectionID!&echo.
  52.       echo Name. . . . . . . . . . . . : !Name!
  53.       echo ConfigManagerErrorCode. . . : !ConfigManagerErrorCode!
  54.       echo NetConnectionStatus . . . . : !NetConnectionStatus!
  55.       echo eTimeOfLastReset. . . . . . : !TimeOfLastReset!
  56.     )
  57.   )
  58. )
  59. start NIC.TXT
  60. exit /b
  61. :getIP
  62. (set %1=!%1:^"=!&set %1=!%1:{=!&set %1=!%1:}=!)
  63. exit /b
  64. :getEnum
  65. for /f "tokens=1,2* delims= " %%a in (%1) do (
  66.   if /i "!getValue!"=="Y" set "%2%%a=%%c"
  67.   if /i "%%a"==":%2" set getValue=Y
  68.   if /i "%%a"==":end:%2" set getValue=N
  69. )
  70. exit /b
  71. :NetConnectionStatus enum
  72. 0 (0x0) Disconnected
  73. 1 (0x1) Connecting
  74. 2 (0x2) Connected
  75. 3 (0x3) Disconnecting
  76. 4 (0x4) Hardware not present
  77. 5 (0x5) Hardware disabled
  78. 6 (0x6) Hardware malfunction
  79. 7 (0x7) Media disconnected
  80. 8 (0x8) Authenticating
  81. 9 (0x9) Authentication succeeded
  82. 10 (0xA) Authentication failed
  83. 11 (0xB) Invalid address
  84. 12 (0xC) Credentials required
  85. :end:NetConnectionStatus enum
  86. :ConfigManagerErrorCode enum
  87. 0 (0x0) Device is working properly.
  88. 1 (0x1) Device is not configured correctly.
  89. 2 (0x2) Windows cannot load the driver for this device.
  90. 3 (0x3) Driver for this device might be corrupted, or the system may be low on memory or other resources.
  91. 4 (0x4) Device is not working properly. One of its drivers or the registry might be corrupted.
  92. 5 (0x5) Driver for the device requires a resource that Windows cannot manage.
  93. 6 (0x6) Boot configuration for the device conflicts with other devices.
  94. 7 (0x7) Cannot filter.
  95. 8 (0x8) Driver loader for the device is missing.
  96. 9 (0x9) Device is not working properly. The controlling firmware is incorrectly reporting the resources for the device.
  97. 10 (0xA) Device cannot start.
  98. 11 (0xB) Device failed.
  99. 12 (0xC) Device cannot find enough free resources to use.
  100. 13 (0xD) Windows cannot verify the device's resources.
  101. 14 (0xE) Device cannot work properly until the computer is restarted.
  102. 15 (0xF) Device is not working properly due to a possible re-enumeration problem.
  103. 16 (0x10) Windows cannot identify all of the resources that the device uses.
  104. 17 (0x11) Device is requesting an unknown resource type.
  105. 18 (0x12) Device drivers must be reinstalled.
  106. 19 (0x13) Failure using the VxD loader.
  107. 20 (0x14) Registry might be corrupted.
  108. 21 (0x15) System failure. If changing the device driver is ineffective, see the hardware documentation. Windows is removing the device.
  109. 22 (0x16) Device is disabled.
  110. 23 (0x17) System failure. If changing the device driver is ineffective, see the hardware documentation.
  111. 24 (0x18) Device is not present, not working properly, or does not have all of its drivers installed.
  112. 25 (0x19) Windows is still setting up the device.
  113. 26 (0x1A) Windows is still setting up the device.
  114. 27 (0x1B) Device does not have valid log configuration.
  115. 28 (0x1C) Device drivers are not installed.
  116. 29 (0x1D) Device is disabled. The device firmware did not provide the required resources.
  117. 30 (0x1E) Device is using an IRQ resource that another device is using.
  118. 31 (0x1F) Device is not working properly. Windows cannot load the required device drivers.
  119. :end:ConfigManagerErrorCode enum
  120. :AdapterType enum
  121. 0 (0x0) Ethernet 802.3
  122. 1 (0x1) Token Ring 802.5
  123. 2 (0x2) Fiber Distributed Data Interface (FDDI)
  124. 3 (0x3) Wide Area Network (WAN)
  125. 4 (0x4) LocalTalk
  126. 5 (0x5) Ethernet using DIX header format
  127. 6 (0x6) ARCNET
  128. 7 (0x7) ARCNET (878.2)
  129. 8 (0x8) ATM
  130. 9 (0x9) Wireless
  131. 10 (0xA) Infrared Wireless
  132. 11 (0xB) Bpc
  133. 12 (0xC) CoWan
  134. 13 (0xD) 1394
  135. :end:AdapterType enum
复制代码

作者: busboy    时间: 2013-12-18 22:00

这个还不错,要是不用生成新的文本,能直接显示在批处理之中更方便
作者: 34205    时间: 2015-2-24 00:03

这个还不错这个还不错这个还不错




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