Last active
October 11, 2019 07:37
-
-
Save pcqpcq/c458fa7586bdbabdaea29ca97b68fc87 to your computer and use it in GitHub Desktop.
shell script for ping multiple dns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set PING_COUNT=10 | |
set SKIP_LINE=13 | |
set DNS_ADDRESS_ARRAY=168.126.63.1 ^ | |
168.126.63.2 ^ | |
223.5.5.5 ^ | |
223.6.6.6 ^ | |
168.95.1.1 ^ | |
168.95.192.1 ^ | |
203.80.96.10 ^ | |
203.80.96.9 ^ | |
61.10.0.130 ^ | |
61.10.1.130 ^ | |
208.67.222.222 ^ | |
208.67.220.220 ^ | |
202.14.67.4 ^ | |
202.14.67.14 ^ | |
198.153.194.1 ^ | |
198.153.192.1 ^ | |
8.8.8.8 ^ | |
8.8.4.4 ^ | |
rem 起始准备 | |
echo. | |
echo. | |
rem 遍历dns数组 | |
(for %%d in (%DNS_ADDRESS_ARRAY%) do ( | |
rem 检查dns连接 | |
ping -n %PING_COUNT% -l 64 %%d > pinglog.txt | |
rem 输出检查结果 | |
for /f "skip=%SKIP_LINE% delims=" %%i in (pinglog.txt) do ( | |
echo %%i | |
) | |
rem 分隔 | |
echo. | |
echo. | |
)) | |
rem 清除log文件 | |
del pinglog.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PING_COUNT=10 | |
DNS_ADDRESS_ARRAY=(168.126.63.1 \ | |
168.126.63.2 \ | |
223.5.5.5 \ | |
223.6.6.6 \ | |
168.95.1.1 \ | |
168.95.192.1 \ | |
203.80.96.10 \ | |
203.80.96.9 \ | |
61.10.0.130 \ | |
61.10.1.130 \ | |
208.67.222.222 \ | |
208.67.220.220 \ | |
202.14.67.4 \ | |
202.14.67.14 \ | |
198.153.194.1 \ | |
198.153.192.1 \ | |
8.8.8.8 \ | |
8.8.4.4 \ | |
) | |
# 起始准备 | |
echo -e "\n" | |
# 遍历dns数组 | |
for dns in ${DNS_ADDRESS_ARRAY[@]}; | |
do | |
# 检查dns连接 | |
ping -c $PING_COUNT $dns > pinglog.txt | |
# 输出检查结果 | |
while read line | |
do | |
if [[ $line == *"round-trip"* || $line == *"packets transmitted"* || $line == *"ping statistics"* ]]; then | |
echo $line | |
fi | |
done < 'pinglog.txt' | |
# 分隔 | |
echo -e "\n" | |
done | |
# 清除log文件 | |
rm -f pinglog.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment