标题: [已解决]批处理根据MAC地址改计算机名、IP、掩码、网关、DNS [打印本页]
作者: w3528033 时间: 2008-11-20 00:25 标题: [已解决]批处理根据MAC地址改计算机名、IP、掩码、网关、DNS
我对DOS不懂,只会些基本的命令,以下的代码谁能帮我精简下?
要能达到改计算机名,IP,掩码,网关,DNS就行,不用检查那么多网卡;删除临时文件和在“开始”菜单的“启动”中创建快捷方式我不需要那么多功能。而且此代码我保存为.BAT执行提示无效的本地连接??
或者哪个兄弟有时间帮重编个,谢谢。
下面还有2个批在附件里,想研究的拿去- @ECHO OFF
- @cls
- ECHO ::::::::::::::::::::::::::::::::::::::::::::::::::::
- ECHO :: GHOST完成后根据网卡MAC自动设置机名和IP的批处理 ::
- ECHO ::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- ::::清空环境变量
- Set IPAddress=
- Set strMac=
- Set MacAddress=
- Set CName=
- Set scfile=
- Set sc=
- Set MacWMIC=
- Set ConnName=
-
- If not "%1"=="run" Goto setboot
-
- cd/d %temp%
-
- REM ::::请手动修改列表
- ECHO [ComputerName] [MacAddress] [IPAddress] >iplist.txt
- ECHO LX001 00-04-01-02-09-90 192.168.1.1 >>iplist.txt
- ECHO LX002 00-04-01-02-09-91 192.168.1.2 >>iplist.txt
- ECHO LX003 00-04-01-02-09-92 192.168.1.3 >>iplist.txt
- ECHO LX004 00-04-01-02-09-93 192.168.1.4 >>iplist.txt
- ECHO LXASP 00-03-FF-93-39-9F 192.168.0.10 >>iplist.txt
-
- REM ::::请手动修改子网掩码
- Set mask=255.255.255.0
- REM ::::请手动修改默认网关
- Set gway=192.168.0.1
-
- ECHO :::: 开始查找网卡 ::::
-
- ::::获取机器的TCP/IP 配置
- if exist ipconfig.txt del ipconfig.txt
- ipconfig /all >ipconfig.txt
-
- ::::分离出机器的物理地址,并保存到 ( phyaddr.txt) 文件中
- if exist phyaddr.txt del phyaddr.txt
- if exist phyaddr1.txt del phyaddr1.txt
- find "Physical Address" ipconfig.txt >phyaddr.txt
-
- Set sc=1
- Set scfile=phyaddr.txt
- goto scan
-
- ::::多网卡时,扫描每个网卡MAC地址
- :rescan1
- Set sc=%sc%1
- Set scfile=phyaddr1.txt
- find /v "%strMac%" phyaddr.txt >%scfile%
- Goto scan
-
- :rescan2
- Set sc=%sc%1
- Set scfile=phyaddr.txt
- find /v "%strMac%" phyaddr1.txt >%scfile%
- Goto scan
-
- :scan
- ::::从(c:\phyaddr.txt)文件中取得物理地址字符串,并赋给变量"MacAddress"
- for /f "skip=2 tokens=12" %%M in (%scfile%) do set strMac=%%M
-
- ::::以变量"strMac"为关键字搜索(iplist.txt)中相同的字符串行,并保存到(PCCfg.txt)
- find "%strMac%" iplist.txt >PCCfg.txt
-
- ::::找出机器名(从"PCCfg.txt"中分离出 机器名字段,并赋给变量"CName")
- for /f "skip=2 tokens=1" %%N in (PCCfg.txt) do set CName=%%N
-
- if not "%CName%"=="" Goto found
- ::::支持最多扫描5个网卡
- If "%sc%"=="11111" Goto failed
- If "%sc%"=="1" Goto rescan1
- if %scfile%==phyaddr.txt Goto rescan1
- if %scfile%==phyaddr1.txt Goto rescan2
- :found
- ECHO 本机 MAC: %strMac%
- ECHO 目标名称: %CName%
-
- ::::显示IP地址. (从"PCCfg.txt"中分离出 IP地址字段,并赋给变量"IPAddress")
- for /f "skip=2 tokens=3" %%I in (PCCfg.txt) do set IPAddress=%%I
- ECHO 目标地址: %IPAddress%
-
- ::::显示网卡MAC地址.(从"PCCfg.txt"中分离出 MAC地址字段,并赋给变量"MacAddress")
- for /f "skip=2 tokens=2" %%M in (PCCfg.txt) do set MacAddress=%%M
- ECHO 目标 MAC: %MacAddress%
-
- ::::创建注册表文件
- ::::用变量"%CName%"去替换实际的机器名
- ECHO Windows Registry Editor Version 5.00 >PCName.reg
- ECHO.>>PCName.reg
- ECHO [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName] >>PCName.reg
- ECHO "ComputerName"="%CName%" >>PCName.reg
- ECHO.>>PCName.reg
- ECHO [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] >>PCName.reg
- ECHO "NV Hostname"="%CName%" >>PCName.reg
- ECHO "Hostname"="%CName%" >>PCName.reg
-
- ECHO :::: 正在更改设置 ::::
- REM ::::导入注册表文件。用的时候把" :: "去掉
- regedit /s PCName.reg
-
- ::::找出MAC地址所对应的连接名称
- for /f "tokens=1,2,3,4,5,6 delims=-" %%A in ("%MacAddress%") do set MacWMIC=%%A:%%B:%%C:%%D:%%E:%%F
-
- WMIC NIC WHERE "MACAddress='%MacWMIC%' AND NetConnectionID!=NULL" GET NetConnectionID /value >phyaddr.txt
-
- WMIC NIC WHERE "MACAddress='%MacWMIC%' AND NetConnectionID!=NULL" GET NetConnectionID /value >phyaddr.txt
-
- Type phyaddr.txt >phyaddr1.txt
-
- for /f "skip=2 tokens=2* delims==" %%A in (phyaddr1.txt) do set ConnName=%%A
-
- Echo 连接名称: %ConnName%
-
- REM ::::修改IP地址。用的时候把" :: "去掉
- netsh interface ip set address name="%ConnName%" source=static addr=%IPAddress% mask=%mask% gateway=%gway% gwmetric=1
-
- ECHO :::: 准备重启 ::::
- setlocal
-
- ::::删除临时文件
- echo [version] > ipdel.inf
- echo signature=$chicago$ >> ipdel.inf
- echo [defaultinstall] >> ipdel.inf
- echo delfiles=delfiles1 >> ipdel.inf
- echo delfiles=delfiles2 >> ipdel.inf
- echo [destinationdirs] >> ipdel.inf
- echo delfiles1=16391 >> ipdel.inf
- echo delfiles2=01 >> ipdel.inf
- echo [delfiles1] >> ipdel.inf
- echo ip.lnk,,,1 >> ipdel.inf
- echo [delfiles2] >> ipdel.inf
- echo PCCfg.txt,,,1 >> ipdel.inf
- echo PCName.reg,,,1 >> ipdel.inf
- echo ipconfig.txt,,,1 >> ipdel.inf
- echo iplist.txt,,,1 >> ipdel.inf
- echo phyaddr1.txt,,,1 >> ipdel.inf
- echo phyaddr.txt,,,1 >> ipdel.inf
- RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 128 .\ipdel.inf
- del ipdel.inf
-
- ::::准备重启的文件
- echo [version] > reboot.inf
- echo signature=$chicago$ >> reboot.inf
- echo [defaultinstall] >> reboot.inf
- REM ::::立即重启。用的时候把" :: "去掉
- RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 1 .\reboot.inf
- del reboot.inf
-
- Goto end
-
- :setboot
- Echo [Version] >ipstart.inf
- Echo Signature="$CHICAGO$" >>ipstart.inf
- Echo [DefaultInstall] >>ipstart.inf
- Echo UpdateInis = AddLink >>ipstart.inf
- Echo [AddLink] >>ipstart.inf
- Echo setup.ini, progman.groups,, "group1=""%%16391%%""" >>ipstart.inf
- Echo setup.ini, group1,,"""IP"",""""""%%01%%\ip.bat"""" run"",,,,"""",""ip.bat""" >>ipstart.inf
- RUNDLL32.EXE SETUPAPI.DLL,InstallHinfSection DefaultInstall 128 .\ipstart.inf
- del ipstart.inf
-
- Echo 完成在“开始”菜单的“启动”中创建快捷方式。
- Echo 请在此之后使用GHOST创建此分区的GHO镜像文件。
- pause
-
- Goto End
-
- :failed
- ECHO !!!! 查找网卡失败 !!!!
- :end
复制代码
- echo off
- title 扫描即将开始 制作
- color a
- cls
- echo.
- echo ------------------------------------------------------------
- echo QQ:欢迎交流
- echo.
- echo 本批处理是扫描内网IP、MAC地址和计算机名的,并自动保存文件TXT文件
- echo.
- echo 再利用“自动改IP.bat”实现自动改IP、计算机名、网络号、DNS、网关等
- echo.
- echo 并自动安装冰点,将冰点改名为DF.exe,并保存在“自动改IP.bat”同目录下
- echo.
- echo 为了扫描到的结果正确,请按照正确格式输入
- echo.
- echo ---------------------PS:制作不容易,请保留版权----------------------
- set /p gateway=请输入内网网关:
- set /p dns1=请输入你的首选DNS:
- set /p dns2=请输入你的备用DNS:
- echo gateway %gateway% >info.txt
- echo DNS1 %dns1% >>info.txt
- echo DNS2 %dns2% >>info.txt
- echo MAC IP 计算机名 >>info.txt
- set rc=0
- set /p ipq=请输入内网IP的前3位(如192.168.0):
- set /p iph=请输入你要扫描的IP起始段(IP的最后一位):
- set /p con1=请输入你要扫描的数量:
- set /a con= %iph%+%con1%
- :scan
- set ip=%ipq%.%iph%
- ping -n 1 -w 1 %ip% >nul
- title 正在检测 %ip% 制作
- if %errorlevel% GEQ 1 goto dz
- for /f "tokens=1" %%i in ('nbtstat -a %ip% ^| find /i "UNIQUE" ^| find /i "00"') do set pcname=%%i
- for /f "tokens=4" %%i in ('nbtstat -a %ip% ^| find /i "MAC Address"') do set mac=%%i
- echo %mac% %ip% %pcname% >>info.txt
- set /a iph=%iph%+1
- set /a rc=%rc%+1
- if %iph% GTR %con% goto end
- goto scan
- :dz
- echo %ip%不在线,无法扫描!
- set /a iph=%iph%+1
- if %iph% GTR %con% goto end
- goto scan
- :end
- title 扫描完毕 制作
- echo 扫描完毕!!
- @echo 共扫描%con%台PC。其中%rc%台PC在线!!
- pause
-
- echo off
- for /f "tokens=2" %%i in ('findstr /r /i "dns1" info.txt') do Set dns1=%%i
- for /f "tokens=2" %%i in ('findstr /r /i "dns2" info.txt') do Set dns2=%%i
- for /f "tokens=2" %%i in ('findstr /r /i "gateway" info.txt') do Set gateway=%%i
- for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| find /i "Physical Address"') do Set mac=%%i
- for /f "tokens=2,3 " %%i in ('findstr /r /i "%mac%" info.txt') do set ip=%%i & set pcname=%%j
- for /f "tokens=4,5 delims=. " %%i in ('findstr /r /i "%mac%" info.txt') do Set /a netkey=%%i+%%j
- ::判断本地连接 赋值lj
- for /f "tokens=3 delims=: " %%i in ('ipconfig ^|findstr /r "adapter"') do set lj=%%i
- @echo 本地连接名为:%lj%
- @echo 本机IP为:%ip%
- @echo 本机计算机名为:%pcname%
- @echo 本机首选DNS为:%dns1%
- @echo 本机备用DNS为:%dns2%
- @echo 内网网关为:%gateway%
- @echo 本地网络号为:%netkey%
- @echo 正在修改IP等信息。。。。
- ping 127.0.0.1 -n 2 >nul
- netsh interface ip set address name="%lj%" source=static addr=%ip% mask=255.255.255.0 gateway=%gateway% gwmetric=1
- netsh interface ip set dns name="%lj%" source=static addr=%dns1%
- netsh interface ip add dns "%lj%" %dns2% index=2
- REG add "HKLM\SYSTEM\CurrentControlSet\Services\NwlnkIpx\Parameters" /v VirtualNetworkNumber /t REG_DWORD /d %netkey% /f
- ::更改计算机名
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v ComputerName /t reg_sz /d %pcname% /f
- REG add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "Hostname" /t REG_SZ /d %pcname% /f
- REG add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t REG_SZ /d %pcname% /f
复制代码
- @echo off
- color 0a
- setlocal EnableDelayedExpansion
- title 自动改IP,计算机名,批处理,新东方红网吧专用版 by 彬
- set mask=255.255.255.0
- set gateway=192.168.1.1
- set DNS1=202.96.128.86
- set DNS2=202.96.128.166
- set DNS3=61.144.56.100
- set DNS4=202.96.128.68
- echo.
- echo. 完成获取资料,请检查正确后按确认键开始执行修改任务
- echo.
- for /f "tokens=2 delims=:" %%M in ('ipconfig /all^|find /i "Physical Address"') do set Mac=%%M
- echo. 本机 MAC地址: %Mac% (硬件获取)
- set PCMAC=%MAC:~1%
- echo.
- for /f "tokens=1" %%a in ('type MAC.ini^|find /i "%PCMac%"') do (set pcname=%%a)
- echo 本机计算机名: %pcname% (动态获取)
- echo.
- for /f "tokens=2" %%b in ('type MAC.ini^|find /i "%PCMac%"') do (set myip=%%b)
- echo 本机 IP 地址: %myip% (动态获取)
- echo.
- echo.*************************************************************************
- echo 子网掩码: %mask% (静态获取)
- echo 本机网关: %gateway% (静态获取)
- echo. 本机DNS1: %DNS1% (静态获取)
- echo. 本机DNS2: %DNS2% (静态获取)
- echo. 本机DNS3: %DNS3% (静态获取)
- echo. 本机DNS4: %DNS4% (静态获取)
- echo.
- pause
- echo 修改计算机器名ing...
- reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam" /v @ /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v "ComputerName" /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName" /v "ComputerName" /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Services\Eventlog" /v "ComputerName" /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v "ComputerName" /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "Hostname" /t REG_SZ /d "%pcname%" /f
- echo.
- echo 开始设置网卡 IP 地址,掩码,网关,DNS
- netsh interface ip set address name="本地连接" source=static addr=%myip% mask=%mask% gateway=%gateway% gwmetric=1
- netsh interface ip set dns name="本地连接" source=static addr=%DNS1%
- netsh interface ip add dns name="本地连接" addr=%DNS2% index=2
- netsh interface ip add dns name="本地连接" addr=%DNS3% index=3
- netsh interface ip add dns name="本地连接" addr=%DNS4% index=4
- echo 设置网卡 IP 地址,掩码,网关,DNS完成
- echo.
- ipconfig/all
- echo.
- pause
- shutdown -r -t 0
复制代码
作者: Batcher 时间: 2008-11-20 00:55
所发代码若不止一行,请务必用code标记把代码部分首尾括起来,以便他人复制;
Q: 如何用code把代码扩起来?
A: http://bbs.bathome.net/thread-404-1-1.html
作者: w3528033 时间: 2008-11-20 12:27
谢谢指导
改正了
作者: w3528033 时间: 2008-11-20 21:41
千心万苦又到了1帖,“一看就知道是我想要的”
可是运行了没效果,机器名改没了,IP没改动,还搞的断网了。可能是他给注册表没添加对东西的缘故吧
行家路过给指点指点....
- @echo off
- color 0a
- setlocal EnableDelayedExpansion
- title 根据MAC地址自动修改计算机名、IP地址、掩码、网关、DNS(批处理) By Netboy
- set mask=255.255.255.0
- set gateway=192.168.1.1
- set DNS1=202.96.128.86
- set DNS2=202.96.128.166
- echo.
- echo. 完成获取资料,请检查正确后按确认键开始执行修改任务
- echo.*************************************************************************
- echo.
- for /f "tokens=2 delims=:" %%M in ('ipconfig /all^|find /i "Physical Address"') do set Mac=%%M
- echo. 本机 MAC地址 (硬件获取): %Mac%
- set PCMAC=%MAC:~1%
- echo.
- for /f "tokens=1" %%a in ('type MAC.ini^|find /i "%PCMac%"') do (set pcname=%%a)
- echo 本机计算机名 (动态获取): %pcname%
- echo.
- for /f "tokens=2" %%b in ('type MAC.ini^|find /i "%PCMac%"') do (set myip=%%b)
- echo 本机 IP 地址 (动态获取): %myip%
- echo.
- echo.*************************************************************************
- echo 子网掩码 (静态获取): %mask%
- echo 本机网关 (静态获取): %gateway%
- echo. 本机DNS1 (静态获取): %DNS1%
- echo. 本机DNS2 (静态获取): %DNS2%
- echo.
- pause
- echo 修改计算机器名进行中...
- reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam" /v @ /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v "ComputerName" /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName" /v "ComputerName" /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Services\Eventlog" /v "ComputerName" /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" /v "ComputerName" /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t REG_SZ /d "%pcname%" /f
- reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" /v "Hostname" /t REG_SZ /d "%pcname%" /f
- echo.
- echo 开始设置网卡IP地址、掩码、网关、DNS
- netsh interface ip set address name="本地连接" source=static addr=%myip% mask=%mask% gateway=%gateway% gwmetric=1
- netsh interface ip set dns name="本地连接" source=static addr=%DNS1%
- netsh interface ip add dns name="本地连接" addr=%DNS2% index=2
- echo 设置网卡IP地址、掩码、网关、DNS完成
- echo.
- ipconfig/all
- echo.
- pause
- shutdown -r -t 3
-
-
- 下面这个就是你要搜集来的MAC地址,注意格式。
-
- 引用内容
- [计算机名] [IP地址] [MAC地址]
- NB-100 192.168.0.100 00-E0-A0-0C-BD-56
- NB-101 192.168.0.101 00-E0-A0-0E-D0-E4
- NB-102 192.168.0.102 00-E0-A0-0E-DC-8C
- NB-103 192.168.0.103 00-E0-A0-0C-B0-C4
-
复制代码
说明:1、MAC地址可以通过各种工具收集(如:LanHelper)。
2、set mask、set gateway、set DNS1、set DNS2 自己根据实际修改。
3、如果还有DNS3、DNS4的话,自己在上面添加即可。
4、如果要实现全自动操作,将批处理的pause去掉即可。
5、批处理最后的 shutdown -r -t 3 是等待3秒后机子自动重启,自己根据实际需要修改
[ 本帖最后由 w3528033 于 2008-11-20 21:42 编辑 ]
作者: w3528033 时间: 2008-11-22 11:05
热心的强人,你在哪里??????
作者: wxcute 时间: 2008-11-22 11:13
根据 ipconfig/all 找出相应的数据,定义变量后再进行设置就好了。
作者: w3528033 时间: 2008-11-23 10:06
ipconfig/all 不会用,举个例子吧,我好照猫画虎,呵呵
作者: wxcute 时间: 2008-11-23 11:19
直接修改 IP、掩码、网关、DNS,
“本地连接” 改为你自己的连接名字。
更改计算机名你采用 4 楼的所有 “reg add” 部分,与下面的合在一起就行了。- @echo off
- for /f "tokens=1* delims=:" %%i in (ip.ini) do set "%%i=%%j"
- echo 正在更改 IP 等,请稍后……
- netsh interface ip set address "本地连接" static %IP% %Mask% %Gateway% 1 1>nul
- netsh interface ip set dns "本地连接" static %DNS% primary>nul
- echo 更改 IP 完成。
- pause>nul
复制代码
配置文件 ip.ini(自己修改其中的地址)- IP:192.168.1.17
- Mask:255.255.255.0
- Gateway:192.168.1.1
- DNS:192.168.1.3
复制代码
ipconfig/all 用于显示 IP 等信息,按你的要求应该是不需要用到。如果你不需要比对原来的 IP 等信息的话,直接用上面的来修改就行了。
作者: w3528033 时间: 2008-11-23 22:56
太谢谢了,搞懂了!
还想请教下,怎么将INI文件内容追加进该BAT里。什么格式?
2个文件(INI和BAT)还得弄个文件夹放。要能合并成1个BAT就清爽了!呵呵
作者: Batcher 时间: 2008-11-24 16:45 标题: 回复 9楼 的帖子
echo命令就是干这个用的- @echo off
- :::::::::::::::::::::::::::::::::::::
- >ip.ini echo IP:192.168.1.17
- >>ip.ini echo Mask:255.255.255.0
- >>ip.ini echo Gateway:192.168.1.1
- >>ip.ini echo DNS:192.168.1.3
- :::::::::::::::::::::::::::::::::::::
- for /f "tokens=1* delims=:" %%i in (ip.ini) do set "%%i=%%j"
- echo 正在更改 IP 等,请稍后……
- netsh interface ip set address "本地连接" static %IP% %Mask% %Gateway% 1 1>nul
- netsh interface ip set dns "本地连接" static %DNS% primary>nul
- echo 更改 IP 完成。
- pause>nul
复制代码
作者: terse 时间: 2008-11-24 18:04
下面的试试如何
你可以先 SET 你自己需要的- @echo off&Setlocal Enabledelayedexpansion
- set "name=youname"
- 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
- set IP=192.168.0.2
- set MASK=255.255.255.0
- set GATEWAY=192.168.0.1
- set DNS=192.168.0.1
- netsh interface ip set address "本地连接" static %IP% %Mask% %GATEWAY% 1 >nul 2>nul
- netsh interface ip set dns "本地连接" static %DNS% >nul 2>nul
- pause
复制代码
作者: w3528033 时间: 2008-11-24 22:07
我是说是否能把事先准备好的MAC对应IP和机器名的INI文件的内容集合到BAT里,实现2合1,INI文件内容如下:
[计算机名] [IP地址] [MAC地址]
NB-100 192.168.0.100 00-E0-A0-0C-BD-56
NB-101 192.168.0.101 00-E0-A0-0E-D0-E4
NB-102 192.168.0.102 00-E0-A0-0E-DC-8C
如4楼的BAT里要靠调用1个名为MAC.INI的配置文件才能根据已搜索到的MAC地址去自动修改IP,机器名
作者: terse 时间: 2008-11-25 00:29
原帖由 w3528033 于 2008-11-24 22:07 发表
我是说是否能把事先准备好的MAC对应IP和机器名的INI文件的内容集合到BAT里,实现2合1,INI文件内容如下:
NB-101 192.168.0.101 00-E0 ...
这样呢?
- @echo off
- set MASK=255.255.255.0
- set GATEWAY=192.168.0.1
- set DNS=192.168.0.1
- for /f "tokens=12 delims= " %%i in ('ipconfig /all^|find /i "Physical Address"') do set mac=%%i
- for /f "tokens=1,2*" %%i in ('ipconfig /all^|find "Ethernet adapter"') do set Ethernet=%%k
- for /f "tokens=1,2" %%i in ('more /e +13 %0 ^|find /i "%mac:~,-1%"') do set "name=%%i"&set "IP=%%j"
- 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
- netsh interface ip set address "%Ethernet:~,-2%" static %IP% %Mask% %GATEWAY% 1 >nul 2>nul
- netsh interface ip set dns "%Ethernet:~,-2%" static %DNS% >nul 2>nul
- pause&exit
- NB-100 192.168.0.100 00-E0-A0-0C-BD-56
- NB-101 192.168.0.101 00-1A-4D-9C-82-87
- NB-102 192.168.0.102 00-E0-A0-0E-DC-8C
复制代码
作者: w3528033 时间: 2008-12-3 21:42
强!!!完美了!!!
谢谢!!!!!!
作者: 6589600 时间: 2008-12-4 01:11
- @echo off
- color 0a
- setlocal EnableDelayedExpansion
- set MASK=255.255.255.0
- set GATEWAY=192.168.123.254
- set DNS1=202.99.192.68
- set DNS2=219.150.32.132
- echo.
- echo. 完成获取资料,请检查正确后按确认键开始执行修改任务
- echo.*************************************************************************
- echo.
- for /f "tokens=12 delims= " %%i in ('ipconfig /all^|find /i "Physical Address"') do set mac=%%i
- echo. 本机 MAC地址 (硬件获取): %Mac%
- for /f "tokens=1,2*" %%i in ('ipconfig /all^|find "Ethernet adapter"') do set Ethernet=%%k
- for /f "tokens=1,2" %%i in ('more /e +13 %0 ^|find /i "%mac:~,-1%"') do set "name=%%i"&set
-
- "IP=%%j"
- echo 本机 IP 地址 (动态获取): %ip%
- echo.
- echo.*************************************************************************
- pause
- 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
- netsh interface ip set address "%Ethernet:~,-2%" static %IP% %Mask% %GATEWAY% 1 >nul
-
- 2>nul
- netsh interface ip set dns "%Ethernet:~,-2%" static %DNS1% >nul 2>nul
- netsh interface ip set dns "%Ethernet:~,-2%" static %DNS2% >nul 2>nul
- pause&exit
- NB-100 192.168.0.100 00-E0-A0-0C-BD-56
- NB-101 192.168.0.101 00-1A-4D-9C-82-87
- NB-105 192.168.1.102 00-e0-4d-a6-10-8f
复制代码
综合一下。呵呵
[ 本帖最后由 6589600 于 2008-12-4 01:13 编辑 ]
作者: ctrl_119 时间: 2009-4-10 14:38
我照着楼上的弄了一个 bat 怎么重视查找不到~~计算机名称和ip地址呀
下面是我的bat文件内容~~~大虾们帮我看看是哪出了问题呀
能查出MAC 就是查不出其他信息。
@echo off
set MASK=255.255.255.0
set GATEWAY=192.168.1.1
set DNS=192.168.1.1
echo.
echo. 完成获取资料,请检查正确后按确认键开始执行修改任务
echo.*************************************************************************
echo.
for /f "tokens=12 delims= " %%i in ('ipconfig /all^|find /i "Physical Address"') do set mac=%%i
echo. 本机 MAC地址 (硬件获取): %Mac%
for /f "tokens=1,2*" %%i in ('ipconfig /all^|find "Ethernet adapter"') do set Ethernet=%%k
echo 本机计算机名 (动态获取): %pcname%
for /f "tokens=1,2" %%i in ('more /e +13 %0 ^|find /i "%mac:~,-1%"') do set "name=%%i"&set "IP=%%j"
echo 本机 IP 地址 (动态获取): %myip%
echo.
echo.*************************************************************************
echo 子网掩码 (静态获取): %mask%
echo 本机网关 (静态获取): %gateway%
echo. 本机DNS (静态获取): %DNS%
echo.
pause
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
netsh interface ip set address "%Ethernet:~,-2%" static %IP% %Mask% %GATEWAY% 1 >nul 2>nul
netsh interface ip set dns "%Ethernet:~,-2%" static %DNS% >nul 2>nul
pause&exit
s0101 192.168.1.101 00:E0:A0:1D:0C:C2
s0102 192.168.1.102 00:E0:81:08:41:7C
s0103 192.168.1.103 00:E0:81:03:9F:FB
s0104 192.168.1.104 00:E0:81:08:32:B7
s0105 192.168.1.105 00:E0:A0:1D:0C:E0
s0106 192.168.1.106 00:E0:81:03:6D:6A
s0107 192.168.1.107 00:E0:81:07:F6:68
s0108 192.168.1.108 00:E0:81:08:69:E7
s0109 192.168.1.109 00:E0:81:03:CA:1A
s0110 192.168.1.110 00:E0:81:08:3B:F9
s0111 192.168.1.111 00:E0:81:08:30:95
s0112 192.168.1.112 00:E0:81:07:78:43
s0113 192.168.1.113 00:E0:A0:1C:B0:88
s0114 192.168.1.114 00:E0:81:07:E9:11
s0115 192.168.1.115 00:E0:81:07:F2:C5
s0116 192.168.1.116 00:E0:81:08:5C:F5
s0117 192.168.1.117 00:E0:81:03:A7:62
s0118 192.168.1.118 00:E0:A0:1C:B3:F4
s0119 192.168.1.119 00:E0:A0:1C:EA:4E
s0120 192.168.1.120 00:E0:81:08:67:36
s0121 192.168.1.121 00:E0:A0:1C:B3:F9
s0122 192.168.1.122 00:E0:81:03:9F:25
s0123 192.168.1.123 00:E0:81:07:5B:67
s0124 192.168.1.124 00:E0:81:07:F2:83
s0125 192.168.1.125 00:E0:81:03:A0:F8
s0126 192.168.1.126 00:E0:A0:14:0C:07
s0127 192.168.1.127 00:E0:81:03:B2:71
s0129 192.168.1.129 00:E0:81:07:5E:F2
s0130 192.168.1.130 00:E0:81:03:78:AC
s0131 192.168.1.131 00:E0:81:07:E7:35
s0132 192.168.1.132 00:E0:81:03:C5:A8
s0133 192.168.1.133 00:E0:81:08:45:22
s0134 192.168.1.134 00:E0:81:08:71:50
s0135 192.168.1.135 00:E0:81:03:BA:13
s0136 192.168.1.136 00:E0:81:03:CF:E5
s0137 192.168.1.137 00:E0:81:07:85:0F
s0138 192.168.1.138 00:E0:81:03:B9:4C
s0139 192.168.1.139 00:E0:81:03:B8:49
s0140 192.168.1.140 00:E0:81:08:5F:11
s0141 192.168.1.141 00:E0:81:08:69:3F
s0142 192.168.1.142 00:E0:61:06:E8:F1
s0143 192.168.1.143 00:E0:81:03:51:25
s0144 192.168.1.144 00:E0:81:07:A2:65
s0145 192.168.1.145 00:E0:A0:14:2D:77
s0146 192.168.1.146 00:E0:81:07:E0:38
s0147 192.168.1.147 00:E0:81:03:CA:BB
s0149 192.168.1.149 00:E0:81:03:63:94
s0150 192.168.1.150 00:E0:81:07:38:91
STUDENT 192.168.1.254 00:50:8D:4D:A7:A7
[ 本帖最后由 ctrl_119 于 2009-4-10 14:40 编辑 ]
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |