用法為dhcp2ip 192.168.0.X(假設檔名為dhcp2ip.bat)
用途為同時擁有Public IP(動態轉靜態)和Private IP
這個BAT在XP下使用正常,今天剛換成WIN7(X64)
發現這個BAT無法使用,執行後即出現下列錯誤訊息
********** DHCP query error. **********
可能的話勞請fyi大神修改一下這個BAT檔!感激不盡!
@echo off
cls
echo *** This batch file will query DHCP server and add a second static IP ***
echo .
if %1. == . goto syntax
if not %4. == . goto syntax
set local_ip=%1
set netmask=%2
set adapter=%3
if %2. == . set netmask=255.255.255.0
if %3. == . set adapter=區域連線
echo IP Address. . . . . . . . . . . . : %local_ip%
echo Subnet Mask . . . . . . . . . . . : %netmask%
echo Ethernet adapter. . . . . . . . . : %adapter%
echo .
pause
echo Resetting local IP in order to disable DHCP client...
netsh interface ip set address %adapter% static %local_ip% %netmask%
if errorlevel 1 goto adapter_error
echo Query DHCP server...
netsh interface ip set address %adapter% source=dhcp
rem echo %errorlevel%
if errorlevel 1 goto error
ipconfig /all | find "Lease"
echo .
echo Checking IP...
:check
echo .
ipconfig | find /N ". . :" >%temp%\ipconfig.txt
set addr=
FOR /F "tokens=18 delims=de " %%i IN (%temp%\ipconfig.txt) DO set addr=%%i
if %addr%.==. goto error
set mask=
FOR /F "tokens=18 delims=be " %%i IN (%temp%\ipconfig.txt) DO set mask=%%i
if %mask%.==. goto error
set gateway=
FOR /F "tokens=19 delims=ae " %%i IN (%temp%\ipconfig.txt) DO set gateway=%%i
if %gateway%.==. goto check
echo Setting first static IP...
netsh interface ip set address %adapter% static %addr% %mask% %gateway% 10
if errorlevel 1 goto adapter_error
echo Adding second static IP...
netsh interface ip add address %adapter% %local_ip% %netmask%
if errorlevel 1 goto adapter_error
goto end
:syntax
echo Syntax: %0 {Local IP Address} [Subnet Mask] [Adapter]
echo .
echo Example:
echo %0 192.168.0.1
echo %0 192.168.0.1 255.255.255.0
echo %0 192.168.0.1 255.255.255.0 區域連線
goto end
:adapter_error
echo ********** Command error. **********
goto end
:error
echo ********** DHCP query error. **********
:end
if exist %temp%\ipconfig.txt del %temp%\ipconfig.txt
ipconfig
echo .
pause