ping and telnet timeout

Hello,
I need help, I have the following which save in the result file ping and telnet:port test.

Basically the script works but I should implement a check on ping and telnet command so that ping has 5 seconds threshold and telnet (more important) 10 seconds. Over that threshold ping and telnet should be interrupted giving a negative answer. Can someone help me?

thank you

#!/bin/sh
DNS="10.0.0.1"
HTTP="80"
SMTPSERVER="10.33.23.32"
POPSERVER="10.33.23.54"
SMTP="25"
POP="110"
 
echo "++++START++++" >> result
if ping ${DNS} | grep -w "alive"
then
  echo "DNS * Test ping DNS:" " >> result; echo ${DNS} " is OK" >> result
else
  echo "DNS * Test ping DNS:" >> result; echo ${DNS} " is DOWN " >> result
fi
echo "++++END++++" >> result
echo >> result
echo "++++START++++" >> result
echo "SMTP Test:" >> result; echo "b" | telnet -e "b" ${SMTPSE
RVER} ${SMTP} && echo ${SMTPSERVER}:${SMTP} " is OK" >> result
echo "++++END++++" >> result
echo >> result
echo "++++START++++" >> result
echo "POP Test:" >> result; echo "b" | telnet -e "b" ${POPSERV
ER} ${POP} && echo  ${POPSERVER}:${POP}" is OK" >> result
echo "++++END++++" >> result