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

此代碼適用雙網卡、雙IP、雙DNS,試試看!
  1. @ECHO OFF&Setlocal EnableDelayedExpansion
  2. FOR /F "tokens=1,2* delims==" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
  3.     IF /I "%%A"=="Domain" SET "Domain=%%B"
  4.     IF /I "%%A"=="Name" SET "Name=%%B"&ECHO.電腦名稱: !Name:~,-1!&ECHO.工作群組: !Domain:~,-1!
  5. )
  6. FOR /F "tokens=1,2* delims==" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
  7.     IF /I "%%A"=="DefaultIPGateway" SET "Gateway=%%B"
  8.     IF /I "%%A"=="Description" SET "CardName=%%B"
  9.     IF /I "%%A"=="DNSServerSearchOrder" SET "DNS=%%B"
  10.     IF /I "%%A"=="IPAddress" SET "IP=%%B"
  11.     IF /I "%%A"=="IPSubnet" SET "Subnet=%%B"&ECHO.網卡名稱: !CardName:~,-1!&ECHO.IP  位址: !IP:~1,-2!&ECHO.網路遮罩: !Subnet:~1,-2!&ECHO.預設閘道: !Gateway:~1,-2!&ECHO.DNS 服務: !DNS:~1,-2!&ECHO.
  12. )
  13. ECHO.                            Press any key to exit...
  14. PAUSE >Nul
复制代码

TOP

多谢楼上。

计算机一般都是1个网卡。但绑定的是2个DNS

这种情况,如何修改代码,显示出2个DNS来?

TOP

17# ygqiang

若是電腦上只有一張網卡那只會秀一張網卡信息,
DNS,IP,Gateway 亦是如此,您試了就明白!!

TOP

新的小问题:
  1. echo ------------修改后的结果:------------
  2. @ECHO OFF&Setlocal EnableDelayedExpansion
  3. FOR /F "tokens=1,2* delims==" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
  4.     IF /I "%%A"=="Domain" SET "Domain=%%B"
  5.     IF /I "%%A"=="Name" SET "Name=%%B"&ECHO.计算机名----: !Name:~,-1!&ECHO.工作组------: !Domain:~,-1!
  6. )
  7. FOR /F "tokens=1,2* delims==" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
  8.     IF /I "%%A"=="DefaultIPGateway" SET "Gateway=%%B"
  9.     IF /I "%%A"=="Description" SET "CardName=%%B"
  10.     IF /I "%%A"=="DNSServerSearchOrder" SET "DNS=%%B"
  11.     IF /I "%%A"=="IPAddress" SET "IP=%%B"
  12.     IF /I "%%A"=="IPSubnet" SET "Subnet=%%B"&ECHO.IP地址------: !IP:~1,-2!&ECHO.子网掩码----: !Subnet:~1,-2!&ECHO.网关--------: !Gateway:~1,-2!&ECHO.DNS---------: !DNS:~1,-2!&ECHO.
  13. )
  14. ECHO.                            Press any key to exit...
  15. PAUSE >Nul
复制代码
这个bat文件,运行以后,ip地址显示的是:"10.10.94.184"

如何将ip地址显示成:10.10.94.184

就是说:如何将2个""符合去掉?

TOP

原来显示的是:

TOP

字符截取   :~1,-2!  到  :~2,-3!

TOP

字符截取   :~1,-2!  到  :~2,-3!
terse 发表于 2011-6-22 11:36


多谢。

但DNS显示会出现一点小问题。
  1. echo ------------修改后的结果:------------
  2. @ECHO OFF&Setlocal EnableDelayedExpansion
  3. FOR /F "tokens=1,2* delims==" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
  4.     IF /I "%%A"=="Domain" SET "Domain=%%B"
  5.     IF /I "%%A"=="Name" SET "Name=%%B"&ECHO.计算机名----: !Name:~,-1!&ECHO.工作组------: !Domain:~,-1!
  6. )
  7. FOR /F "tokens=1,2* delims==" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
  8.     IF /I "%%A"=="DefaultIPGateway" SET "Gateway=%%B"
  9.     IF /I "%%A"=="Description" SET "CardName=%%B"
  10.     IF /I "%%A"=="DNSServerSearchOrder" SET "DNS=%%B"
  11.     IF /I "%%A"=="IPAddress" SET "IP=%%B"
  12.     IF /I "%%A"=="IPSubnet" SET "Subnet=%%B"&ECHO.IP地址------: !IP:~2,-3!&ECHO.子网掩码----: !Subnet:~2,-3!&ECHO.网关--------: !Gateway:~2,-3!&ECHO.DNS---------: !DNS:~2,-3!&ECHO.
  13. )
  14. ECHO.                            Press any key to exit...
  15. PAUSE >Nul
复制代码

TOP

顶下,又出现一点小问题。

TOP

各位帮忙解决下啊,谢谢了。

TOP

这样试下呢?
  1. echo ------------修改后的结果:------------
  2. @ECHO OFF&Setlocal EnableDelayedExpansion
  3. set _Name=计算机名&set _Domain=工作组&set _DefaultIPGateway=网关
  4. set _IPAddress=IP地址&set _IPSubnet=子网掩码&set _DNSServerSearchOrder=DNS
  5. FOR /F "tokens=*" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
  6.     FOR /F "tokens=*" %%i in ("%%A") do set %%i
  7. )
  8. FOR /F "tokens=*" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
  9.    FOR /F "tokens=*" %%i in ("%%A") do set %%i
  10. )
  11. for %%i in (Domain Name DefaultIPGateway DNSServerSearchOrder IPAddress IPSubnet) do (
  12.     set %%i=!%%i:{=!
  13.     set %%i=!%%i:}=!
  14.     set %%i=!%%i:"=!
  15.     echo !_%%i!: !%%i:,=!
  16. )
  17. ECHO.                            Press any key to exit...
  18. PAUSE >Nul
复制代码

TOP

本帖最后由 ygqiang 于 2011-6-23 11:26 编辑
  1. echo ------------修改后的结果:------------
  2. @ECHO OFF&Setlocal EnableDelayedExpansion
  3. set _Name=计算机名&set _Domain=工作组&set _DefaultIPGateway=网关
  4. set _IPAddress=IP地址&set _IPSubnet=子网掩码&set _DNSServerSearchOrder=DNS
  5. FOR /F "tokens=*" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
  6.     FOR /F "tokens=*" %%i in ("%%A") do set %%i
  7. )
  8. FOR /F "tokens=*" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
  9.    FOR /F "tokens=*" %%i in ("%%A") do set %%i
  10. )
  11. for %%i in (Name Domain IPAddress IPSubnet DefaultIPGateway DNSServerSearchOrder) do (
  12.     set %%i=!%%i:{=!
  13.     set %%i=!%%i:}=!
  14.     set %%i=!%%i:"=!
  15.     echo !_%%i!: !%%i:,=!
  16. )
  17. ECHO.                            Press any key to exit...
  18. PAUSE >Nul
复制代码
这个代码可以。出现1个小问题
1、dns显示的是(中间应该隔开啊):
DNS: 10.10.0.510.10.0.6

TOP

  1. echo ------------修改后的结果:------------
  2. @ECHO OFF&Setlocal EnableDelayedExpansion
  3. set _Name=--计算机名&set _Domain=----工作组&set _IPAddress=----IP地址
  4. set _IPSubnet=--子网掩码&set _DefaultIPGateway=------网关&set _DNSServerSearchOrder=-------DNS
  5. FOR /F "tokens=*" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
  6.     FOR /F "tokens=*" %%i in ("%%A") do set %%i
  7. )
  8. FOR /F "tokens=*" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
  9.    FOR /F "tokens=*" %%i in ("%%A") do set %%i
  10. )
  11. for %%i in (Name Domain IPAddress IPSubnet DefaultIPGateway DNSServerSearchOrder) do (
  12.     set %%i=!%%i:{=!
  13.     set %%i=!%%i:}=!
  14.     set %%i=!%%i:"=!
  15.     echo !_%%i!: !%%i:,=  !  
  16. )
  17. ECHO.                            Press any key to exit...
  18. PAUSE >Nul
  19. exit
复制代码
问题解决。谢谢各位

TOP

返回列表