mirror of
https://github.com/pi-hole/pi-hole
synced 2025-01-09 07:30:56 +00:00
add ping gateway function
This commit is contained in:
parent
8fd9a22d18
commit
107babe8f4
@ -246,19 +246,69 @@ detect_ip_addresses() {
|
|||||||
if [[ -n ${ip_addr_list} ]]; then
|
if [[ -n ${ip_addr_list} ]]; then
|
||||||
# Local iterator
|
# Local iterator
|
||||||
local i
|
local i
|
||||||
echo -e " ${INFO} IPv${protocol}"
|
echo -e " ${TICK} IPv${protocol} on ${PIHOLE_INTERFACE}"
|
||||||
# display the contents to the user
|
for i in "${!ip_addr_list[@]}"; do
|
||||||
echo -e " ${INFO} Interface: ${PIHOLE_INTERFACE}"
|
echo -e " [$i] ${ip_addr_list[$i]}"
|
||||||
for i in "${ip_addr_list[@]}"; do
|
|
||||||
echo -e " ${INFO} $i"
|
|
||||||
done
|
done
|
||||||
# Othwerwise explain that the protocol is not configured
|
# Othwerwise explain that the protocol is not configured
|
||||||
else
|
else
|
||||||
echo -e " ${CROSS} No IPv${protocol} found on ${PIHOLE_INTERFACE}"
|
echo -e " ${CROSS} No IPv${protocol} found on ${PIHOLE_INTERFACE}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ping_gateway() {
|
||||||
|
# First argument should be a 4 or a 6
|
||||||
|
local protocol="${1}"
|
||||||
|
# If the protocol is 6,
|
||||||
|
if [[ ${protocol} == "6" ]]; then
|
||||||
|
# use ping6
|
||||||
|
local cmd="ping6"
|
||||||
|
# and Google's public IPv6 address
|
||||||
|
local public_address="2001:4860:4860::8888"
|
||||||
|
# Otherwise,
|
||||||
|
else
|
||||||
|
# use ping
|
||||||
|
local cmd="ping"
|
||||||
|
# and Google's public IPv4 address
|
||||||
|
local public_address="8.8.8.8"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Find the default gateway using IPv4 or IPv6
|
||||||
|
local gateway
|
||||||
|
gateway="$(ip -${protocol} route | grep default | cut -d ' ' -f 3)"
|
||||||
|
|
||||||
|
# If the gateway variable has a value (meaning a gateway was found),
|
||||||
|
if [[ -n "${gateway}" ]]; then
|
||||||
|
# Let the user know we will ping the gateway for a response
|
||||||
|
echo -e " ${INFO} Trying three pings on IPv${protocol} gateway at ${gateway}..."
|
||||||
|
# Try to quietly ping the gateway 3 times, with a timeout of 3 seconds, using numeric output only,
|
||||||
|
# on the pihole interface, and tail the last three lines of the output
|
||||||
|
# If pinging the gateway is not successful,
|
||||||
|
if ! ping_cmd="$(${cmd} -q -c 3 -W 3 -n ${gateway} -I ${PIHOLE_INTERFACE} | tail -n 3)"; then
|
||||||
|
# let the user know
|
||||||
|
echo -e " ${CROSS} Gateway did not respond."
|
||||||
|
# and return an error code
|
||||||
|
return 1
|
||||||
|
# Otherwise,
|
||||||
|
else
|
||||||
|
# show a success
|
||||||
|
echo -e " ${TICK} Gateway responded."
|
||||||
|
# and return a success code
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_networking() {
|
||||||
|
echo_current_diagnostic "Networking"
|
||||||
|
detect_ip_addresses "4"
|
||||||
|
ping_gateway "4"
|
||||||
|
detect_ip_addresses "6"
|
||||||
|
ping_gateway "6"
|
||||||
|
}
|
||||||
|
|
||||||
parse_file() {
|
parse_file() {
|
||||||
# Set the first argument passed to tihs function as a named variable for better readability
|
# Set the first argument passed to tihs function as a named variable for better readability
|
||||||
local filename="${1}"
|
local filename="${1}"
|
||||||
@ -344,5 +394,6 @@ check_ftl_version
|
|||||||
diagnose_setup_variables
|
diagnose_setup_variables
|
||||||
diagnose_operating_system
|
diagnose_operating_system
|
||||||
processor_check
|
processor_check
|
||||||
|
check_networking
|
||||||
check_critical_dependencies
|
check_critical_dependencies
|
||||||
check_dnsmasq_d
|
check_dnsmasq_d
|
||||||
|
Loading…
Reference in New Issue
Block a user