[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[网络连接] [分享]纯批处理获取已连接的网络适配器的相关参数信息

本帖最后由 pcl_test 于 2015-11-29 22:35 编辑

  1. @echo off&color 0e
  2. ::正在连接中的IP地址查询
  3. for /f "delims=" %%i in ('getmac /v /nh /fo:csv') do (
  4. if /i not "%%~i"=="%%~nxi" (
  5.   for /f "tokens=1,2,3,* delims=," %%j in ("%%i") do (
  6.    if not defined #_network_name set "#_network_name=%%~j"
  7.    if not defined #_network_adapter set "#_network_adapter=%%~k"
  8.    if not defined #_network_mac set "#_network_mac=%%~l"
  9.   (echo,网络名称: %%~j
  10.   echo,适 配 器: %%~k
  11.   echo,物理地址: %%~l)
  12. )
  13. for /f "tokens=1,* delims=_" %%m in ("%%~nxi") do (
  14.   for %%o in ("dhcpipaddress","dhcpsubnetmask","dhcpdefaultgateway","dhcpnameserver","ipaddress","subnetmask","defaultgateway","nameserver","lease") do (
  15.    reg.exe query "hklm\system\controlset001\services\tcpip\parameters\interfaces\%%n" /v "%%~o" >nul 2>nul&&(
  16.     for /f "tokens=1,* delims=)" %%p in ('reg.exe query "hklm\system\controlset001\services\tcpip\parameters\interfaces\%%n" /v "%%~o" /z') do (
  17.      if /i not "%%~nxp"=="%%n" for /f "tokens=1,* delims=, " %%r in ("%%q") do (
  18.      if /i "%%~o"=="dhcpipaddress" (
  19.      if not defined #_network_ipaddress set "#_network_ipaddress=%%r"
  20.      echo,动态 IP 地址: %%r
  21. ) else if /i "%%~o"=="dhcpsubnetmask" (
  22. if not defined #_network_subnetmask set "#_network_subnetmask=%%r"
  23. echo,动态子网掩码: %%r
  24. ) else if /i "%%~o"=="dhcpdefaultgateway" (
  25. if not defined #_network_defaultgateway set "#_network_defaultgateway=%%r"
  26. echo,动态 网 关 : %%r
  27. ) else if /i "%%~o"=="dhcpnameserver" (
  28. if not defined #_network_nameserver_main set "#_network_nameserver_main=%%r"
  29. if not defined #_network_nameserver_spare set "#_network_nameserver_spare=%%s"
  30. echo,动态 dns服务: %%r,%%s
  31. ) else if /i "%%~o"=="ipaddress" (
  32. if not defined #_network_subnetmask set "#_network_subnetmask=%%r"
  33. echo,静态 IP 地址: %%r
  34. ) else if /i "%%~o"=="subnetmask" (
  35. if not defined #_network_subnetmask set "#_network_subnetmask=%%r"
  36. echo,静态子网掩码: %%r
  37. ) else if /i "%%~o"=="defaultgateway" (
  38. if not defined #_network_defaultgateway set "#_network_defaultgateway=%%r"
  39. echo,静态 网 关 : %%r
  40. ) else if /i "%%~o"=="nameserver" (
  41. if not defined #_network_nameserver_main set "#_network_nameserver_main=%%r"
  42. if not defined #_network_nameserver_spare set "#_network_nameserver_spare=%%s"
  43. echo,静态 dns服务: %%r,%%s
  44. ) else if /i "%%~o"=="lease" (
  45. if not defined #_network_lease set/a "#_network_lease=%%r"
  46. call echo,租约时间[秒]: %%#_network_lease%%
  47. )
  48. )
  49. )
  50. )
  51. )
  52. )
  53. )
  54. )
  55. set #_network_
  56. pause
复制代码

不改格式了代码太多了,自己改下吧
这么好的论坛你上哪找,运行测试环境为6.1.7601-64
注:请遵守互联网信息安全,勿用于非法用途

  1. @echo off
  2. wmic nic where NetEnabled="true" get NetConnectionID /value
  3. wmic nicconfig where IPEnabled="true" get Description,DefaultIPGateway,DHCPLeaseObtained,DHCPLeaseExpires,DHCPServer,DNSServerSearchOrder,IPAddress,IPSubnet,MACAddress,SettingID /value
  4. pause
复制代码

TOP

回复 2# pcl_test
哈哈,我不必找wmic中的nic和nicconfig参数了,你早该出来整理下WMIC的所有应用具体参数了
这么好的论坛你上哪找,运行测试环境为6.1.7601-64
注:请遵守互联网信息安全,勿用于非法用途

TOP

回复 3# /zhqsystem/zhq


你说的找参数是什么情况?
get * 不是可以得到所有的属性和对应的值么

TOP

回复 4# DAIC
每个wmic的分项参数都不一样,所以要合集就像这样wmic os get caption,localdatetime,osarchitecture /value,红色区域的参数不是相同的需要整理的是这些,有助于高效匹配结合
这么好的论坛你上哪找,运行测试环境为6.1.7601-64
注:请遵守互联网信息安全,勿用于非法用途

TOP

代码完善优化:
  1. @echo off
  2. for /f "delims=" %%i in ('call wmic nic where netenabled^="true" get * /value')do (
  3. for /f "delims=" %%j in ("%%i")do (
  4.   for /f "tokens=1,* delims==" %%k in ("%%j")do (
  5.    for %%m in ("netconnectionid","productname","macaddress","guid")do if /i "%%~k"=="%%~m" set "#nic_%%j"
  6.    if /i "%%~k"=="productname" (
  7.      setlocal enabledelayedexpansion
  8.      echo,网络连接: !#nic_netconnectionid!
  9.      echo,网络名称: !#nic_productname!
  10.      echo,网络 MAC: !#nic_macaddress!
  11.      echo,网络GUID: !#nic_guid!
  12.      setlocal disabledelayedexpansion
  13.    )
  14.   )
  15. )
  16. )
  17. for /f "delims=" %%i in ('call wmic nicconfig where macaddress^="%%#nic_macaddress%%" get * /value')do (
  18. for /f "delims=" %%j in ("%%i")do (
  19.   for /f "tokens=1,* delims==" %%k in ("%%j")do (
  20.    for %%m in ("ipaddress","ipsubnet","defaultipgateway","dnsserversearchorder")do if /i "%%~k"=="%%~m" set "#nicconfig_%%j"
  21.    if defined #nicconfig_%%~k for %%m in ("{","}") do call set "#nicconfig_%%~k=%%#nicconfig_%%~k:%%~m=%%"
  22.    if /i "%%~k"=="ipsubnet" (
  23.     (setlocal enabledelayedexpansion)>nul 2>nul
  24.      echo,I P 地址: !#nicconfig_ipaddress!
  25.      echo,子网掩码: !#nicconfig_ipsubnet!
  26.      echo,默认网关: !#nicconfig_defaultipgateway!
  27.      echo,dns 服务: !#nicconfig_dnsserversearchorder!
  28.     (setlocal disabledelayedexpansion)>nul 2>nul
  29.    )
  30.   )
  31. )
  32. )
  33. pause
复制代码
这么好的论坛你上哪找,运行测试环境为6.1.7601-64
注:请遵守互联网信息安全,勿用于非法用途

TOP

返回列表