【批处理】切换hosts文件

@echo.
@echo           -----------------------------------------
@echo            本命令将自动为“本地连接”填写以下内容:
@echo               IP地址:  192.168.0.*   
@echo               网关:    192.168.0.1
@echo               主DNS:    202.102.24.34
@echo               备DNS:    202.102.24.35
@echo           -----------------------------------------
@echo.
@echo.
@echo 没有接入局域网的用户,开机时,系统因搜索不到IP地址,进系统的速度稍慢,请在
@echo 本地连接填上IP地址(任意),就可加快系统的启动速度。所以本批处理仅是为单机拨
@echo 号上网的用户准备的,局域网用户请不要理会本批处理,乱改可能导致您上不了网。
@echo.
@echo.
@echo off

setlocal enabledelayedexpansion

@echo 1.静态IP   2.DHCP   3.已分配地址

set/p slection1=请选择分配IP类型(输入编号即可):

echo ***************************************
@echo.
@echo.



if %slection1%==1 (goto 1)

if %slection1%==2 (goto 2)

if %slection1%==3 (goto 3)

pause

exit

:1

set slection2=

set/p slection2=请输入IP地址:192.168.0.

netsh interface ip set address name="本地连接" source=static addr=192.168.0.%slection2% mask=255.255.255.0 gateway=192.168.0.1 1

@echo IP、MASK、GATEWAY设置完成

netsh interface ip set dns name="本地连接" source=static addr=202.102.24.34 register=PRIMARY

@echo 主DNS设置完成

netsh interface ip add dns name="本地连接" addr=202.102.24.35

@echo 备DNS设置完成

netsh interface ip set wins name="本地连接" source=static addr=none

@echo WINS设置完成

pause



:2

@echo 等待网关分配IP
@echo.
@echo.

ping 127.255.255.255 -n 1 -w 10000 >nul

for /f  "tokens=2 delims=:" %%i in ('ipconfig^|find /i "IP Address"') do echo 当前IP为 %%i

for /f  "tokens=2 delims=:" %%j in ('ipconfig^|find /i "Default Gateway"') do echo 当前IP为 %%j&set char=%%j

ping %%j&& goto :3 || goto :2


pause

:3

@echo 1.yes   2.no
@echo.
@echo.
set/p slection3=是否为内网?

if %slection3%==1 (goto 4)

if %slection3%==2 (goto 5)

:4

echo # Copyright (c) 1993-1999 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 127.0.0.1       localhost>>hosts
echo 12.222.111.11   www.yui.com>>hosts

copy hosts C:/WINDOWS/system32/drivers/etc/hosts




:5

echo # Copyright (c) 1993-1999 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 127.0.0.1       localhost>>hosts
echo 12.222.111.11   www.yui.com>>hosts

copy hosts C:/WINDOWS/system32/drivers/etc/hosts


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值