bash-dns/tools/smtp_test.sh
2023-08-17 22:43:59 -05:00

49 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
get_tool_name() {
echo "SMTP Test"
}
get_tool_description() {
echo "Check SMTP ports of a domain"
}
execute_tool() {
result=""
if [ -n "$domain" ]; then
if [[ "$domain" == *$'\n'* ]]; then
for single_domain in $domain; do
process_domain "$single_domain"
done
else
process_domain "$domain"
fi
else
result="No domains specified."
fi
echo -e "$result"
}
process_domain() {
local single_domain="$1"
result+="\e[1mDomain:\e[93m $single_domain\e[0m\n"
mx_record=$(dig +short MX "$single_domain" | sort -n | head -n 1 | awk '{print $2}')
if [ -n "$mx_record" ]; then
smtp_ports="25 465 587"
ports_status=""
for port in $smtp_ports; do
if nc -z -w3 "$mx_record" "$port"; then
ports_status+="\e[0m$port: \e[32mSuccess\e[0m "
else
ports_status+="\e[0m$port: \e[31mError\e[0m "
fi
done
result+="\e[1mMX Hostname Tested:\e[0m $mx_record \e[1mPorts:\e[0m $ports_status\n"
else
result+="No MX record found for $single_domain\n"
fi
}