注意:多网卡识别未加入,因为多网卡环境不多,所以没有加,我想只要努力,一定可以为我所用的。
@echo off
title AutoIP
ping -n 1 192.168.0.252>nul||goto check_go
if exist \\192.168.0.252\data\ArpBinding.ini COPY \\192.168.0.252\data\ArpBinding.ini %CD%\ArpBinding.ini /y & goto check_go
if exist wget.exe wget -q -N
ftp://192.168.0.252/data/ArpBinding.ini
:check_go
cls
set zwym=255.255.255.0
set Gateway=192.168.0.1
set dns1=220.189.127.106
set dns2=192.168.0.1
set dns3=220.189.127.108
Set PC_IP=0.0.0.0
Set IP=0.0.0.0
set mac=00-00-00-00-00-00
echo %time:~0,8% 检测网络设备...
for /f "tokens=16" %%i in ('ipconfig /all^| find /i "Host Name"') do set pcName=%%i
for /f "tokens=15" %%i in ('ipconfig ^| find /i "ip address"') do set PC_IP=%%i
for /f "tokens=12" %%i in ('ipconfig /all^| find /i "Physical Address"') do set mac=%%i
::读取网维大师ArpBinding.ini
for /f "tokens=1 delims==" %%i in ('type ArpBinding.ini^|find /i "%mac%"') do set IP=%%i
::读取普通的ARP绑定批处理文件
::for /f "tokens=3" %%i in ('find /i "%mac%" "mac.bat"') do set IP=%%i
if %IP%==0 goto ipend
set Ipx=%IP:~10,3%
if %Ipx% lss 2 goto Ipx_end
if %Ipx% geq 254 goto Ipx_end
if %Ipx% lss 10 set a=00& goto Ipx_config
if %Ipx% lss 100 set a=00& set /a a=%a%-0& goto Ipx_config
if %Ipx% lss 255 set a=& goto Ipx_config
:Ipx_config
set Ipx_reg=%a%%Ipx%
set LISTPCNAME=A%Ipx_reg%
set mac1=%mac:~0,2%
set mac2=%mac:~3,2%
set mac3=%mac:~6,2%
set mac4=%mac:~9,2%
set mac5=%mac:~12,2%
set mac6=%mac:~15,2%
set wmicMac=%mac1%:%mac2%:%mac3%:%mac4%:%mac5%:%mac6%
::echo %time:~0,8% 本机 name:%pcName% ^| Mac:%Mac% ^| IP:%PC_IP%
::echo %time:~0,8% 列表 name:%LISTPCNAME% ^| Mac:%Mac% ^| IP:%ip%
if %pcName%==%LISTPCNAME% goto CHECKIP
WMIC computersystem where Name="%pcName%" call Rename Name="%LISTPCNAME%" >nul
reg add HKLM\system\currentcontrolset\control\computername\computername\ /v computername /t reg_sz /d "%LISTPCNAME%" /f >nul
reg add HKLM\system\currentcontrolset\services\tcpip\Parameters\ /v "NV Hostname" /t reg_sz /d "%LISTPCNAME%" /f >nul
echo Windows Registry Editor Version 5.00 >%Ipx_reg%.reg
echo >>%Ipx_reg%.reg
echo "VirtualNetworkNumber"=dword:00000%Ipx_reg% >>%Ipx_reg%.reg
echo >>%Ipx_reg%.reg
echo "VirtualNetworkNumber"=dword:00000%Ipx_reg% >>%Ipx_reg%.reg
regedit /s %Ipx_reg%.reg
del %Ipx_reg%.reg
:CHECKIP
if %PC_IP%==%IP% goto IP1~IP2
echo %time:~0,8% 正在设置本机IP...请稍候
WMIC NICCONFIG WHERE MACAddress="%wmicMac%" call EnableStatic("%ip%"),("%zwym%") >nul
WMIC NICCONFIG WHERE MACAddress="%wmicMac%" call SetGateways("%Gateway%") >nul
WMIC NICCONFIG WHERE MACAddress="%wmicMac%" call SetDNSServerSearchOrder("%dns1%", "%dns2%", "%dns3%") >nul
echo %time:~0,8% 本机IP设置成功!
for /f "tokens=2 delims=&" %%i in ('devcon find pci\* ^| findstr "Ethernet"') do devcon DISABLE *%%i*> nul
for /f "tokens=2 delims=&" %%i in ('devcon find pci\* ^| findstr "Network"') do devcon DISABLE *%%i*> nul
for /f "tokens=2 delims=&" %%i in ('devcon find pci\* ^| findstr "Ethernet"') do devcon ENABLE *%%i*> nul
for /f "tokens=2 delims=&" %%i in ('devcon find pci\* ^| findstr "Network"') do devcon ENABLE *%%i*> nul
echo %time:~0,8% 正在重启网卡...请稍候
ping -n 5 127.1>nul
for /f "tokens=15" %%i in ('ipconfig ^| find /i "ip address"') do set PC_IP=%%i
echo %time:~0,8% IP:%PC_IP%
set m=31
call :echo
:IP1~IP2
echo %time:~0,8% 检测到需设置的IP信息与当前使用的相同,程序退出!
goto ipend
:echo
set /a m-=1
echo %time:~0,8% 剩余 %m% 秒后重启系统!
ping -n 2 127.1>nul
if %m% lss 1 shutdown -r -t 0 && goto ipend
goto echo
:ipend
Last edited by tvzml on 2008-4-14 at 09:21 PM ]