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
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值