Windows 设置网路,Ping地址

“以太网” 为网卡名称,“E:/iptest/iplist.txt”里存放需要ping的ip地址,每行一个

    @echo off
	:main
	echo ================
	echo 1:网络设置
	echo 2:自动获取IP
	echo 3:Ping Ip地址
	echo 4:初始化网路设置
	echo 5:结束
	echo ================
	set /p choice=你的选择:
	echo.
	if "%choice%"=="1" goto initSet
	if "%choice%"=="2" goto dhcpIp
	if "%choice%"=="3" goto pingIp
	if "%choice%"=="4" goto dhcpSet
	if "%choice%"=="5" goto end

	:initSet
	echo IP自动设置开始....
	echo.
	echo 正在设置IP及子网掩码
	cmd /c netsh interface ip set address name="以太网" source=static addr=172.168.1.101 mask=255.255.255.0 gateway=172.168.1.1 gwmetric=1
	echo 正在设置DNS服务器
	cmd /c netsh interface ip set dns name="以太网" source=static addr=192.168.1.1 register=PRIMARY
	echo 正在设置DNS服务器
	cmd /c netsh interface ip add dns name="以太网" addr=172.168.1.1 
	set err=%errorlevel%
	if "%err%"=="0" (
		echo 设置成功 
		goto main
	) else if "%err%"=="1" ( 
		echo 设置失败
		goto main 
	) else (
		echo 错误码:%errorlevel%
		goto main
	)

	:dhcpIp
	echo IP自动设置开始....
	echo.
	echo 自动获取IP地址....
	netsh interface ip set address name = "以太网" source = dhcp
	echo 自动获取DNS服务器....
	netsh interface ip set dns name = "以太网" source = dhcp 
	[@rem](https://my.oschina.net/u/196541) 设置自动获取IP
	set err=%errorlevel%
	if "%err%"=="0" (
		echo 设置成功 
		goto main
	) else if "%err%"=="1" ( 
		echo 设置失败
		goto main 
	) else (
		echo 错误码:%errorlevel%
		goto main
	)

	:pingIp
	echo ping 网路地址开始....
	::获取时间
	set date=%date:~0,4%-%date:~5,2%-%date:~8,2%%time:~0,8%
	::读取iplist进行ping操作
	for /f %%a in (E:/iptest/iplist.txt) do (
	echo IP地址:%%a
	echo %date%begin_ping  %%a: >>checkout.txt
	::执行5次ping且剔除过程
	ping %%a -n 5 |find ")" >>checkout.txt
	echo %date%end_ping  %%a >>checkout.txt
	)
	echo ping 网路地结束....

	:dhcpSet
	netsh interface ip set address name = "以太网" source = dhcp
	netsh interface ip set dns name = "以太网" source = dhcp 
	netsh interface ip set wins name = "以太网" source = dhcp 
	set err=%errorlevel%
	if "%err%"=="0" (
		echo 设置成功 
		goto main
	) else if "%err%"=="1" ( 
		echo 设置失败
		goto main 
	) else (
		echo 错误码:%errorlevel%
		goto main
	)

	:end  
	pause
	exit
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值