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
相關文章
相關標籤/搜索