1. 程式人生 > >Windows 批處理修改hosts指令碼

Windows 批處理修改hosts指令碼

方便修改hosts檔案和加入商家域名,可以儲存.bat指令碼或者打包成.exe執行程式

@echo off
@echo ######################################################
echo                      說明:
echo "請以管理員身份執行此指令碼,注意防毒軟體提示,一定要允許"
echo "如設定有誤,重新執行此指令碼進行選擇即可"
@echo ######################################################

set /p name=請輸入商家域名:
rem echo %name%
cd %systemroot%\system32\drivers\etc rem 刪除原來備份檔案 if exist hosts.bak del hosts.bak rem 重新命名hosts檔案 ren hosts hosts.bak rem 新建hosts檔案 echo 1 0>hosts 1>nul 2>nul :Menu echo 1.電信網路 echo 2.聯通網路 echo 3.行動網路 echo 4.還原Hosts檔案為初始狀態 echo. echo 請根據客戶網路環境選擇對應的選項: :Input set
"network=" set /p network=請輸入您的選項編號(1/2/3/4),按ENTER確定: rem echo %network% if /i "%network%"=="1" goto :CTCC if /i "%network%"=="2" goto :CUCC if /i "%network%"=="3" goto :CMCC if /i "%network%"=="4" goto :RECOVERY echo 輸入錯誤,請重新輸入 &pause>nul&goto Input :CTCC rem 插入電信的地址對映 echo xx.xx.xx.xx www.xxx.com >>hosts echo
xx.xx.xx image.xxx.com >>hosts echo xx.xx.xx.xx upload.xxx.com >>hosts echo xx.xx.xx.xx %name% >>hosts ipconfig/flushdns ping %name% goto End :CUCC rem 插入聯通的地址對映 echo xx.xx.xx.xx www.xx.com >>hosts echo xx.xx.xx.xx image.xx.com >>hosts echo xx.xx.xx.xx upload.xx.com >>hosts echo xx.xx.xx.xx %name% >>hosts ipconfig/flushdns ping %name% goto End :CMCC rem 插入移動的地址對映 echo xx.xx.xx.xx www.xx.com >>hosts echo xx.xx.xx.xx image.xx.com >>hosts echo xx.xx.xx.xx upload.xx.com >>hosts echo xx.xx.xx.xx %name% >>hosts ipconfig/flushdns ping %name% goto End :RECOVERY echo # Copyright (c) 1993-2009 Microsoft Corp.>hosts echo #>>hosts echo # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.>>hosts echo #>>hosts echo # This file contains the mappings of IP addresses to host names. Each>>hosts echo # entry should be kept on an individual line. The IP address should>>hosts echo # be placed in the first column followed by the corresponding host name.>>hosts echo # The IP address and the host name should be separated by at least one>>hosts echo # space.>>hosts echo #>>hosts echo # Additionally, comments (such as these) may be inserted on individual>>hosts echo # lines or following the machine name denoted by a '#' symbol.>>hosts echo #>>hosts echo # For example:>>hosts echo #>>hosts echo # 102.54.94.97 rhino.acme.com # source server>>hosts echo # 38.25.63.10 x.acme.com # x client host>>hosts echo.>>hosts echo # localhost name resolution is handled within DNS itself.>>hosts echo # 127.0.0.1 localhost>>hosts echo # ::1 localhost>>hosts echo.>>hosts goto End :End pause exit