批處理修改IP

  因爲經常出差,每次修改IP都覺得特別麻煩。然後就想到可以用批處理的方式修改IP地址,通過查資料、測試,終於找到了可以在win10下修改IP的批處理(需要以管理員權限運行),不過還不是很完善。

ECHO OFFREM  QBFC Project Options BeginREM  HasVersionInfo: NoREM  Companyname: REM  Productname: REM  Filedescription: REM  Copyrights: REM  Trademarks: REM  Originalname: REM  Comments: REM  Productversion:  0. 0. 0. 0REM  Fileversion:  0. 0. 0. 0REM  Internalname: REM  Appicon: 2.icoREM  QBFC Project Options EndECHO ON@echo off    :: BatchGotAdmin  :-------------------------------------自動獲得管理員權限,臨時  REM  --> Check for permissions  >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"    REM --> If error flag set, we do not have admin.  if '%errorlevel%' NEQ '0' (      echo Requesting administrative privileges...      goto UACPrompt  ) else ( goto gotAdmin )    :UACPrompt      echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"      echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"        "%temp%\getadmin.vbs"      exit /B    :gotAdmin      if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )      pushd "%CD%"      CD /D "%~dp0"  :-------------------------------------- 

color 1

set /p choice=    1.設置公司IP 2.IP自動獲取  3.結束 4.測試 您的選擇:

echo.

if "%choice%"=="1" goto ip1

if "%choice%"=="2" goto ip2

if "%choice%"=="3" goto end

if "%choice%"=="4" goto test

goto main

:ip1

echo IP自動設置開始....

echo.

echo 正在設置IP及子網掩碼

cmd /c netsh interface ip set address name="以太網" source=static addr=192.168.62.178 mask=255.255.255.0 gateway=192.168.62.1 gwmetric=1

echo 正在設置DNS服務器

cmd /c netsh interface ip set dnsservers "以太網" static 114.114.114.114 primary

netsh interface ip add dnsservers "以太網" 8.8.8.8 index=2

echo 設置完成

pause

exit

if errorlevel 2 goto main

if errorlevel 1 goto end

:ip2

color 2

echo IP自動設置開始....

echo.

echo 自動獲取IP地址....

netsh interface ip set address name = "以太網" source = dhcp

echo 自動獲取DNS服務器....

netsh interface ip set dns name = "以太網" source = dhcp

@rem 設置自動獲取IP

echo 設置完成

pause

exit

if errorlevel 2 goto main

if errorlevel 1 goto end

:test

netsh inte***ce ip set address name = "以太網" source = dhcp

netsh inte***ce ip set dns name = "以太網" source = dhcp

netsh inte***ce ip set wins name = "以太網" source = dhcp

CHOICE /C YN /M "退出請按 Y,返回菜單請按 N。"

if errorlevel 2 goto main

if errorlevel 1 goto end

:end 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章