自动修改IP+机器名+DNS+网关+掩码+支持多网卡过滤
减小字体
增大字体
作者:佚名 来源:本站整理 发布时间:2008-4-19 20:26:19

@echo off&title DOS资源站 www.cmdos.net
color 0a
setlocal EnableDelayedExpansion
title 根据MAC自动改计算机名,IP,掩码,网关,DNS.网吧通用版 by 彬QQ43142691-2008-04-13修正
echo.根据MAC半动改计算机名,IP,掩码,网关,DNS.网吧通用版 by 彬QQ43142691-2008-04-13修正
::************************************************************************
::设置掩码(必填)
set mask=255.255.252.0
::设置网关IP(必填)
set gateway=192.168.1.1
::设置DNS1(必填)
set DNS1=202.96.128.86
::设置DNS2(必填)
set DNS2=202.96.128.166
::设置DNS3(可以留空)
set DNS3=61.144.56.100
::设置DNS4(可以留空)
set DNS4=202.96.128.166
::MAC数据表地址(勿改)
set data=新东方红网吧IP数据库.ini
::************************************************************************
set e1=注意:DNS1必须设置,否则出错.
set e2=没有发现MAC数据库,请检查后重新运行.
set e3=MAC数据库中没有此Mac地址记录[或MAC数据库格式错误],无法获取计算机名,请手动修改.
set e4=MAC数据库中没有此Mac地址记录[或MAC数据库格式错误],无法获取本机IP,请手动修改.
if "%DNS1%"=="" (set err=%e1%) & call :er & exit
if "%DNS2%"=="" (set DNS2=没有定义DNS2的地址)
if "%DNS3%"=="" (set DNS3=没有定义DNS3的地址)
if "%DNS4%"=="" (set DNS4=没有定义DNS4的地址)
if not exist %data% (set err=%e2%) & call :er & exit
::************************************************************************
echo.
echo. 获取资料中...
echo.
::************************************************************************
for /f "tokens=12" %%a in ('ipconfig/all^|find /i "Physical Address"') do (set NewMac=%%a)
ipconfig /all>ipconfig.txt
find /i "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 "%mac%" phyaddr.txt >%scfile%
Goto scan
:rescan2
Set sc=%sc%1
Set scfile=phyaddr.txt
find /v "%mac%" phyaddr1.txt >%scfile%
Goto scan
:scan
for /f "skip=2 tokens=12" %%M in (%scfile%) do set mac=%%M
find /i "%mac%" %data% >PCCfg.txt
for /f "skip=2 tokens=4" %%N in (PCCfg.txt) do set pcname=%%N
if not "%pcname%"=="" goto found
::::支持最多扫描5个网卡
If "%sc%"=="11111" goto :eof
If "%sc%"=="1" Goto rescan1
if %scfile%==phyaddr.txt Goto rescan1
if %scfile%==phyaddr1.txt Goto rescan2
:found
for /f "skip=2 tokens=3" %%I in (PCCfg.txt) do set PcMac=%%I
for /f "skip=2 tokens=2" %%M in (PCCfg.txt) do set myIP=%%M
::************************************************************************
if "%pcname%"=="" (set err=%e3%) & call :er & exit
if "%myip%"=="" (set err=%e4%) & call :er & exit
if "%mac%"=="%newmac%" set n1=┏━━━━━━━━━━━━━━━━━━━━━━━━┓
if "%mac%"=="%newmac%" set n2=┃已正确MAC地址:%newmac% (硬件获取)┃应用
if "%mac%"=="%newmac%" set n3=┗━━━━━━━━━━━━━━━━━━━━━━━━┛
if not "%mac%"=="%newmac%" set n1=┏━━━━━━━━━━━━━━━━━━━━━━━━┓
if not "%mac%"=="%newmac%" set n2=┃非正确MAC地址:%newmac% (硬件获取)┃丢弃
if not "%mac%"=="%newmac%" set n3=┗━━━━━━━━━━━━━━━━━━━━━━━━┛
del /q ipconfig.txt phyaddr.txt phyaddr1.txt PCCfg.txt
cls
echo.
echo. 完成获取资料,请确认正确后按回车键开始执行任务
echo.
echo. 本机MAC地址: %Mac% (硬件获取) √
echo.
echo. MAC地址: %PcMac% (硬件获取) √
echo. %n1%
echo. %n2%
echo. %n3%
echo 对应机器名: %pcname% 号计算机 (动态获取) √
echo.
echo 对应的地址: %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%
if "%DNS2%"=="" goto nds3
netsh interface ip add dns name="本地连接" addr=%DNS2% index=2
:dns3
if "%DNS3%"=="" goto nds4
netsh interface ip add dns name="本地连接" addr=%DNS3% index=3
:dns4
if "%DNS4%"=="" goto ok
netsh interface ip add dns name="本地连接" addr=%DNS4% index=4
:ok
cls
echo.
echo. 设置机器名,IP,掩码,网关,DNS完成
echo.
ipconfig/all
echo.
echo. 确认后按回车关闭此窗口
pause>nul2>nul
exit
:er
cls
echo.
echo. 出错啦
mshta vbscript:CreateObject("Wscript.Shell").popup("%err%%Mac%无法识别",10,"出错警告:",64)(window.close)
goto :eof