标题: [网络连接] [分享]纯批处理获取已连接的网络适配器的相关参数信息 [打印本页]
作者: /zhqsystem/zhq 时间: 2015-11-29 21:49 标题: [分享]纯批处理获取已连接的网络适配器的相关参数信息
本帖最后由 pcl_test 于 2015-11-29 22:35 编辑
- @echo off&color 0e
- ::正在连接中的IP地址查询
- for /f "delims=" %%i in ('getmac /v /nh /fo:csv') do (
- if /i not "%%~i"=="%%~nxi" (
- for /f "tokens=1,2,3,* delims=," %%j in ("%%i") do (
- if not defined #_network_name set "#_network_name=%%~j"
- if not defined #_network_adapter set "#_network_adapter=%%~k"
- if not defined #_network_mac set "#_network_mac=%%~l"
- (echo,网络名称: %%~j
- echo,适 配 器: %%~k
- echo,物理地址: %%~l)
- )
- for /f "tokens=1,* delims=_" %%m in ("%%~nxi") do (
- for %%o in ("dhcpipaddress","dhcpsubnetmask","dhcpdefaultgateway","dhcpnameserver","ipaddress","subnetmask","defaultgateway","nameserver","lease") do (
- reg.exe query "hklm\system\controlset001\services\tcpip\parameters\interfaces\%%n" /v "%%~o" >nul 2>nul&&(
- for /f "tokens=1,* delims=)" %%p in ('reg.exe query "hklm\system\controlset001\services\tcpip\parameters\interfaces\%%n" /v "%%~o" /z') do (
- if /i not "%%~nxp"=="%%n" for /f "tokens=1,* delims=, " %%r in ("%%q") do (
- if /i "%%~o"=="dhcpipaddress" (
- if not defined #_network_ipaddress set "#_network_ipaddress=%%r"
- echo,动态 IP 地址: %%r
- ) else if /i "%%~o"=="dhcpsubnetmask" (
- if not defined #_network_subnetmask set "#_network_subnetmask=%%r"
- echo,动态子网掩码: %%r
- ) else if /i "%%~o"=="dhcpdefaultgateway" (
- if not defined #_network_defaultgateway set "#_network_defaultgateway=%%r"
- echo,动态 网 关 : %%r
- ) else if /i "%%~o"=="dhcpnameserver" (
- if not defined #_network_nameserver_main set "#_network_nameserver_main=%%r"
- if not defined #_network_nameserver_spare set "#_network_nameserver_spare=%%s"
- echo,动态 dns服务: %%r,%%s
- ) else if /i "%%~o"=="ipaddress" (
- if not defined #_network_subnetmask set "#_network_subnetmask=%%r"
- echo,静态 IP 地址: %%r
- ) else if /i "%%~o"=="subnetmask" (
- if not defined #_network_subnetmask set "#_network_subnetmask=%%r"
- echo,静态子网掩码: %%r
- ) else if /i "%%~o"=="defaultgateway" (
- if not defined #_network_defaultgateway set "#_network_defaultgateway=%%r"
- echo,静态 网 关 : %%r
- ) else if /i "%%~o"=="nameserver" (
- if not defined #_network_nameserver_main set "#_network_nameserver_main=%%r"
- if not defined #_network_nameserver_spare set "#_network_nameserver_spare=%%s"
- echo,静态 dns服务: %%r,%%s
- ) else if /i "%%~o"=="lease" (
- if not defined #_network_lease set/a "#_network_lease=%%r"
- call echo,租约时间[秒]: %%#_network_lease%%
- )
- )
- )
- )
- )
- )
- )
- )
- set #_network_
- pause
复制代码
不改格式了代码太多了,自己改下吧
作者: pcl_test 时间: 2015-11-29 22:39
- @echo off
- wmic nic where NetEnabled="true" get NetConnectionID /value
- wmic nicconfig where IPEnabled="true" get Description,DefaultIPGateway,DHCPLeaseObtained,DHCPLeaseExpires,DHCPServer,DNSServerSearchOrder,IPAddress,IPSubnet,MACAddress,SettingID /value
- pause
复制代码
作者: /zhqsystem/zhq 时间: 2015-11-29 22:53
回复 2# pcl_test
哈哈,我不必找wmic中的nic和nicconfig参数了,你早该出来整理下WMIC的所有应用具体参数了
作者: DAIC 时间: 2015-11-30 12:02
回复 3# /zhqsystem/zhq
你说的找参数是什么情况?
get * 不是可以得到所有的属性和对应的值么
作者: /zhqsystem/zhq 时间: 2015-11-30 22:59
回复 4# DAIC
每个wmic的分项参数都不一样,所以要合集就像这样wmic os get caption,localdatetime,osarchitecture /value,红色区域的参数不是相同的需要整理的是这些,有助于高效匹配结合
作者: /zhqsystem/zhq 时间: 2016-4-13 15:50
代码完善优化:
- @echo off
- for /f "delims=" %%i in ('call wmic nic where netenabled^="true" get * /value')do (
- for /f "delims=" %%j in ("%%i")do (
- for /f "tokens=1,* delims==" %%k in ("%%j")do (
- for %%m in ("netconnectionid","productname","macaddress","guid")do if /i "%%~k"=="%%~m" set "#nic_%%j"
- if /i "%%~k"=="productname" (
- setlocal enabledelayedexpansion
- echo,网络连接: !#nic_netconnectionid!
- echo,网络名称: !#nic_productname!
- echo,网络 MAC: !#nic_macaddress!
- echo,网络GUID: !#nic_guid!
- setlocal disabledelayedexpansion
- )
- )
- )
- )
- for /f "delims=" %%i in ('call wmic nicconfig where macaddress^="%%#nic_macaddress%%" get * /value')do (
- for /f "delims=" %%j in ("%%i")do (
- for /f "tokens=1,* delims==" %%k in ("%%j")do (
- for %%m in ("ipaddress","ipsubnet","defaultipgateway","dnsserversearchorder")do if /i "%%~k"=="%%~m" set "#nicconfig_%%j"
- if defined #nicconfig_%%~k for %%m in ("{","}") do call set "#nicconfig_%%~k=%%#nicconfig_%%~k:%%~m=%%"
- if /i "%%~k"=="ipsubnet" (
- (setlocal enabledelayedexpansion)>nul 2>nul
- echo,I P 地址: !#nicconfig_ipaddress!
- echo,子网掩码: !#nicconfig_ipsubnet!
- echo,默认网关: !#nicconfig_defaultipgateway!
- echo,dns 服务: !#nicconfig_dnsserversearchorder!
- (setlocal disabledelayedexpansion)>nul 2>nul
- )
- )
- )
- )
- pause
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |