CODE: [Copy to clipboard]
@echo off
color 0a
setlocal EnableDelayedExpansion
title 根据MAC自动改计算机名,IP,掩码,网关,DNS.网吧通用版 by 彬QQ43142691 2008-01-26
echo.根据MAC半动改计算机名,IP,掩码,网关,DNS.网吧通用版 by 彬QQ43142691 2008-01-26
::************************************************************************
::设置掩码(必填)
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=MAC.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 mac=%%a)
for /f "tokens=1" %%b in ('type %data%^|find /i "%mac%"') do (set pcname=%%b)
for /f "tokens=2" %%c in ('type %data%^|find /i "%mac%"') do (set myip=%%c)
if "%pcname%"=="" (set err=%e3%) & call :er & exit
if "%myip%"=="" (set err=%e4%) & call :er & exit
cls
echo.
echo. 完成获取资料,请确认正确后按回车键开始执行任务
echo.
echo. 本机MAC地址: %Mac% (硬件获取)
echo.
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%",10,"出错警告:",64)(window.close)
goto :eof