标题: [注册表类] [已解决]批处理怎样显示计算机名、ip地址、子网掩码、网关信息? [打印本页]
作者: ygqiang 时间: 2011-6-10 11:21 标题: [已解决]批处理怎样显示计算机名、ip地址、子网掩码、网关信息?
请直接看19楼的1个小问题- set /p name=请输您的计算机名:
-
-
- reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v "ComputerName" /t reg_sz /d %name% /f >nul 2>nul
- reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName" /v "ComputerName" /t reg_sz /d %name% /f >nul 2>nul
-
- reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
- reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "Hostname" /t reg_sz /d %name% /f >nul 2>nul
-
-
-
- reg add "HKLM\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName" /v "ComputerName" /t REG_SZ /d "%name%" /f
- reg add "HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters" /v "NV Hostname" /t REG_SZ /d "%name%" /f
- reg add "HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters" /v "Hostname" /t REG_SZ /d "%name%" /f
- reg add "HKLM\SYSTEM\ControlSet002\Control\ComputerName\ComputerName" /v "ComputerName" /t REG_SZ /d "%name%" /f
-
-
-
- set/p slection1=请输入IP地址(只输最后1位):
- netsh interface ip set address name="本地连接" source=static addr="10.10.94.%slection1%" mask=255.255.255.0 gateway=10.10.94.1 gwmetric=1
-
-
-
-
- wmic computersystem where Name="%COMPUTERNAME%" call JoinDomainOrWorkgroup Name="LIBYW"
- echo 修改工作组完毕
-
-
-
- ipconfig/all
- pause
-
-
- exit
复制代码
有个问题请教:
有什么批处理命令,只显示出 计算机名 ip地址 子网掩码 网关 子网的信息?(用ipconfig/all显示的信息太多、太杂乱)
作者: Batcher 时间: 2011-6-10 11:38
用findstr命令过滤一下
作者: 601997526 时间: 2011-6-10 12:52
- @echo off
- ipconfig/all|findstr /c:"Host Name"
- ipconfig/all|findstr /c:"IP Address"
- ipconfig/all|findstr /c:"Subnet Mask"
- ipconfig/all|findstr /c:"Default Gateway"
- ipconfig/all|findstr /c:"DNS Servers"
- pause
复制代码
作者: dennisle 时间: 2011-6-10 14:13
本帖最后由 dennisle 于 2011-6-13 08:03 编辑
- @ECHO OFF&Setlocal EnableDelayedExpansion
- FOR /F "tokens=1,2* delims==" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
- IF /I "%%A"=="Domain" SET "Domain=%%B"
- IF /I "%%A"=="Name" SET "Name=%%B"&ECHO.電腦名稱: !Name:~,-1!&ECHO.工作群組: !Domain:~,-1!
- )
- FOR /F "tokens=1,2* delims=={,}" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
- IF /I "%%A"=="DefaultIPGateway" SET "Gateway=%%B"
- IF /I "%%A"=="Description" SET "CardName=%%B"
- IF /I "%%A"=="DNSServerSearchOrder" SET "DNS=%%B"
- IF /I "%%A"=="IPAddress" SET "IP=%%B"
- IF /I "%%A"=="IPSubnet" SET "Subnet=%%B"&ECHO.網卡名稱: !CardName:~,-1!&ECHO.IP 位址: !IP:~1,-1!&ECHO.網路遮罩: !Subnet:~1,-1!&ECHO.預設閘道: !Gateway:~1,-1!&ECHO.DNS 服務: !DNS:~1,-1!&ECHO.
- )
- ECHO. Press any key to exit...
- PAUSE >Nul
复制代码
作者: ygqiang 时间: 2011-6-11 04:35
@echo off
ipconfig/all|findstr /c:"Host Name"
ipconfig/all|findstr /c:"IP Address"
ipconfig/all|findstr /c:"Subnet Mask"
ipconfig/all|findstr /c:"Default Gateway"
ipconfig/all|findstr /c:"DNS Ser ...
601997526 发表于 2011-6-10 12:52
这个可以解决问题。谢谢
还有个问题,如何加上 显示组名?
作者: Batcher 时间: 2011-6-11 09:39
5# ygqiang 复制代码
作者: ygqiang 时间: 2011-6-13 06:21
systeminfo
这个命令,好像没有显示工作组的方法?
作者: dennisle 时间: 2011-6-13 08:05
本帖最后由 dennisle 于 2011-6-13 08:09 编辑
7# ygqiang
樓主可能需要修改一下標題,
不妨試試4樓代碼!!
作者: Batcher 时间: 2011-6-13 11:27
7# ygqiang
我试了一下,有。
作者: ygqiang 时间: 2011-6-13 13:07
7# ygqiang
樓主可能需要修改一下標題,
不妨試試4樓代碼!!
dennisle 发表于 2011-6-13 08:05
4楼代码不错。
修改如下:- echo ------------修改后的结果:------------
- @ECHO OFF&Setlocal EnableDelayedExpansion
- FOR /F "tokens=1,2* delims==" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
- IF /I "%%A"=="Domain" SET "Domain=%%B"
- IF /I "%%A"=="Name" SET "Name=%%B"&ECHO.计算机名----: !Name:~,-1!&ECHO.工作组------: !Domain:~,-1!
- )
- FOR /F "tokens=1,2* delims=={,}" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
- IF /I "%%A"=="DefaultIPGateway" SET "Gateway=%%B"
- IF /I "%%A"=="Description" SET "CardName=%%B"
- IF /I "%%A"=="DNSServerSearchOrder" SET "DNS=%%B"
- IF /I "%%A"=="IPAddress" SET "IP=%%B"
- IF /I "%%A"=="IPSubnet" SET "Subnet=%%B"&ECHO.IP地址------: !IP:~1,-1!&ECHO.子网掩码----: !Subnet:~1,-1!&ECHO.网关--------: !Gateway:~1,-1!&ECHO.DNS---------: !DNS:~1,-1!&ECHO.
- )
- ECHO. Press any key to exit...
- PAUSE >Nul
复制代码
作者: ygqiang 时间: 2011-6-13 13:08
本帖最后由 ygqiang 于 2011-6-19 18:19 编辑
修改代码如下:- @ECHO OFF
-
- set Addr=192.168.9
- set Mask=255.255.255.128
- set Gway=192.168.9.1
- set usergroup=admin
-
-
- netsh -C interface dump>home.txt
-
- NETDOM.exe MEMBER /JOINWORKGROUP %usergroup%
-
-
-
- set /p name=请输入计算机名:
-
- reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v "ComputerName" /t reg_sz /d %name% /f >nul 2>nul
- reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ActiveComputerName" /v "ComputerName" /t reg_sz /d %name% /f >nul 2>nul
-
- reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
- reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "Hostname" /t reg_sz /d %name% /f >nul 2>nul
-
-
- reg add "HKLM\SYSTEM\ControlSet001\Control\ComputerName\ActiveComputerName" /v "ComputerName" /t REG_SZ /d "%name%" /f
- reg add "HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters" /v "NV Hostname" /t REG_SZ /d "%name%" /f
- reg add "HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters" /v "Hostname" /t REG_SZ /d "%name%" /f
- reg add "HKLM\SYSTEM\ControlSet002\Control\ComputerName\ComputerName" /v "ComputerName" /t REG_SZ /d "%name%" /f
-
-
-
-
- set/p slection1=请输入IP地址(只输最后1位):
-
-
- ::用ipconfig /all命令获取网卡名称。
- FOR /F "tokens=2*" %%i IN ('ipconfig/all^|find /i "Ethernet adapter "') DO set name=%%j
- ::用for命令删除网卡名称后面的冒号。
- FOR /F "tokens=1* delims=:" %%i in ("%name%") do set a=%%i
-
- netsh interface ip set address name="%a%" source=static addr="%Addr%.%slection1%" mask=%Mask% gateway=%Gway% gwmetric=1 >nul 2>nul
-
-
- netsh interface ip delete dns "%a%" all >nul 2>nul
-
-
- ipconfig /flushdns >nul 2>nul
-
-
-
- echo ------------修改后的结果:------------
- @ECHO OFF&Setlocal EnableDelayedExpansion
- FOR /F "tokens=1,2* delims==" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
- IF /I "%%A"=="Domain" SET "Domain=%%B"
- IF /I "%%A"=="Name" SET "Name=%%B"&ECHO.计算机名----: !Name:~,-1!&ECHO.工作组------: !Domain:~,-1!
- )
- FOR /F "tokens=1,2* delims=={,}" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
- IF /I "%%A"=="DefaultIPGateway" SET "Gateway=%%B"
- IF /I "%%A"=="Description" SET "CardName=%%B"
- IF /I "%%A"=="DNSServerSearchOrder" SET "DNS=%%B"
- IF /I "%%A"=="IPAddress" SET "IP=%%B"
- IF /I "%%A"=="IPSubnet" SET "Subnet=%%B"&ECHO.IP地址------: !IP:~1,-1!&ECHO.子网掩码----: !Subnet:~1,-1!&ECHO.网关--------: !Gateway:~1,-1!&ECHO.
- )
- ECHO. Press any key to exit...
- PAUSE >Nul
-
- exit
复制代码
这个代码,遇到2个问题。
1、虽然计算机名已经修改成功,但显示“修改后的结果”的时候,显示的还是旧的计算机名。
这个如何通过批处理刷新下系统?或者刷新下注册表?来显示正确的?
2、“修改后的结果”显示的时候,DNS只显示1个,如何让2个DNS同时显示出来?
作者: ygqiang 时间: 2011-6-19 18:20
出现2个小问题,顶一下...
作者: ygqiang 时间: 2011-6-20 17:43
各位帮忙解决下啊?谢谢
作者: qzwqzw 时间: 2011-6-20 18:30
计算机名修改与全局环境更新一样
都需要向窗口进程发送系统配置更新消息
我尚未看到完全的解决解决方案
目前最好的方案大概还是直接重启吧
作者: ygqiang 时间: 2011-6-20 23:19
多谢楼上。
DNS如何将2个都显示在屏幕上呢?
作者: DennisLee 时间: 2011-6-21 10:12
15# ygqiang
此代碼適用雙網卡、雙IP、雙DNS,試試看!- @ECHO OFF&Setlocal EnableDelayedExpansion
- FOR /F "tokens=1,2* delims==" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
- IF /I "%%A"=="Domain" SET "Domain=%%B"
- IF /I "%%A"=="Name" SET "Name=%%B"&ECHO.電腦名稱: !Name:~,-1!&ECHO.工作群組: !Domain:~,-1!
- )
- FOR /F "tokens=1,2* delims==" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
- IF /I "%%A"=="DefaultIPGateway" SET "Gateway=%%B"
- IF /I "%%A"=="Description" SET "CardName=%%B"
- IF /I "%%A"=="DNSServerSearchOrder" SET "DNS=%%B"
- IF /I "%%A"=="IPAddress" SET "IP=%%B"
- 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.
- )
- ECHO. Press any key to exit...
- PAUSE >Nul
复制代码
作者: ygqiang 时间: 2011-6-21 11:04
多谢楼上。
计算机一般都是1个网卡。但绑定的是2个DNS
这种情况,如何修改代码,显示出2个DNS来?
作者: dennisle 时间: 2011-6-21 12:06
17# ygqiang
若是電腦上只有一張網卡那只會秀一張網卡信息,
DNS,IP,Gateway 亦是如此,您試了就明白!!
作者: ygqiang 时间: 2011-6-22 09:22
新的小问题:- echo ------------修改后的结果:------------
- @ECHO OFF&Setlocal EnableDelayedExpansion
- FOR /F "tokens=1,2* delims==" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
- IF /I "%%A"=="Domain" SET "Domain=%%B"
- IF /I "%%A"=="Name" SET "Name=%%B"&ECHO.计算机名----: !Name:~,-1!&ECHO.工作组------: !Domain:~,-1!
- )
- FOR /F "tokens=1,2* delims==" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
- IF /I "%%A"=="DefaultIPGateway" SET "Gateway=%%B"
- IF /I "%%A"=="Description" SET "CardName=%%B"
- IF /I "%%A"=="DNSServerSearchOrder" SET "DNS=%%B"
- IF /I "%%A"=="IPAddress" SET "IP=%%B"
- 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.
- )
- ECHO. Press any key to exit...
- PAUSE >Nul
复制代码
这个bat文件,运行以后,ip地址显示的是:"10.10.94.184"
如何将ip地址显示成:10.10.94.184
就是说:如何将2个""符合去掉?
作者: ygqiang 时间: 2011-6-22 09:25
原来显示的是:
作者: terse 时间: 2011-6-22 11:36
字符截取 :~1,-2! 到 :~2,-3!
作者: ygqiang 时间: 2011-6-22 13:38
字符截取 :~1,-2! 到 :~2,-3!
terse 发表于 2011-6-22 11:36
多谢。
但DNS显示会出现一点小问题。- echo ------------修改后的结果:------------
- @ECHO OFF&Setlocal EnableDelayedExpansion
- FOR /F "tokens=1,2* delims==" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
- IF /I "%%A"=="Domain" SET "Domain=%%B"
- IF /I "%%A"=="Name" SET "Name=%%B"&ECHO.计算机名----: !Name:~,-1!&ECHO.工作组------: !Domain:~,-1!
- )
- FOR /F "tokens=1,2* delims==" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
- IF /I "%%A"=="DefaultIPGateway" SET "Gateway=%%B"
- IF /I "%%A"=="Description" SET "CardName=%%B"
- IF /I "%%A"=="DNSServerSearchOrder" SET "DNS=%%B"
- IF /I "%%A"=="IPAddress" SET "IP=%%B"
- 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.
- )
- ECHO. Press any key to exit...
- PAUSE >Nul
复制代码
作者: ygqiang 时间: 2011-6-22 18:11
顶下,又出现一点小问题。
作者: ygqiang 时间: 2011-6-23 10:53
各位帮忙解决下啊,谢谢了。
作者: terse 时间: 2011-6-23 10:59
这样试下呢?- echo ------------修改后的结果:------------
- @ECHO OFF&Setlocal EnableDelayedExpansion
- set _Name=计算机名&set _Domain=工作组&set _DefaultIPGateway=网关
- set _IPAddress=IP地址&set _IPSubnet=子网掩码&set _DNSServerSearchOrder=DNS
- FOR /F "tokens=*" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
- FOR /F "tokens=*" %%i in ("%%A") do set %%i
- )
- FOR /F "tokens=*" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
- FOR /F "tokens=*" %%i in ("%%A") do set %%i
- )
-
- for %%i in (Domain Name DefaultIPGateway DNSServerSearchOrder IPAddress IPSubnet) do (
- set %%i=!%%i:{=!
- set %%i=!%%i:}=!
- set %%i=!%%i:"=!
- echo !_%%i!: !%%i:,=!
- )
-
- ECHO. Press any key to exit...
- PAUSE >Nul
复制代码
作者: ygqiang 时间: 2011-6-23 11:17
本帖最后由 ygqiang 于 2011-6-23 11:26 编辑
- echo ------------修改后的结果:------------
- @ECHO OFF&Setlocal EnableDelayedExpansion
- set _Name=计算机名&set _Domain=工作组&set _DefaultIPGateway=网关
- set _IPAddress=IP地址&set _IPSubnet=子网掩码&set _DNSServerSearchOrder=DNS
- FOR /F "tokens=*" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
- FOR /F "tokens=*" %%i in ("%%A") do set %%i
- )
- FOR /F "tokens=*" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
- FOR /F "tokens=*" %%i in ("%%A") do set %%i
- )
-
- for %%i in (Name Domain IPAddress IPSubnet DefaultIPGateway DNSServerSearchOrder) do (
- set %%i=!%%i:{=!
- set %%i=!%%i:}=!
- set %%i=!%%i:"=!
- echo !_%%i!: !%%i:,=!
- )
-
- ECHO. Press any key to exit...
- PAUSE >Nul
复制代码
这个代码可以。出现1个小问题
1、dns显示的是(中间应该隔开啊):
DNS: 10.10.0.510.10.0.6
作者: ygqiang 时间: 2011-6-23 11:33
- echo ------------修改后的结果:------------
- @ECHO OFF&Setlocal EnableDelayedExpansion
- set _Name=--计算机名&set _Domain=----工作组&set _IPAddress=----IP地址
- set _IPSubnet=--子网掩码&set _DefaultIPGateway=------网关&set _DNSServerSearchOrder=-------DNS
- FOR /F "tokens=*" %%A IN ('WMIC Path Win32_ComputerSystem Get Domain^,Name /Value 2^>Nul') DO (
- FOR /F "tokens=*" %%i in ("%%A") do set %%i
- )
- FOR /F "tokens=*" %%A IN ('WMIC NICConfig WHERE "IPEnabled=TRUE" GET DefaultIPGateway^,Description^,DNSServerSearchOrder^,IPAddress^,IPSubnet /value 2^>Nul') DO (
- FOR /F "tokens=*" %%i in ("%%A") do set %%i
- )
-
- for %%i in (Name Domain IPAddress IPSubnet DefaultIPGateway DNSServerSearchOrder) do (
- set %%i=!%%i:{=!
- set %%i=!%%i:}=!
- set %%i=!%%i:"=!
- echo !_%%i!: !%%i:,= !
- )
-
- ECHO. Press any key to exit...
- PAUSE >Nul
-
- exit
复制代码
问题解决。谢谢各位
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |