我对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
复制代码
|