Created
May 5, 2016 20:06
-
-
Save dhyegocalota/dd783fe9cf2918b027c1a39b08b523f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/sh | |
error() { echo "$@" 1>&2; } | |
domain_files=$1 | |
if [ -z $domain_files ]; then | |
error "What is the file with the domains?" | |
exit 1 | |
fi | |
while read domain; do | |
echo "Looking for [$(echo $domain)]..." | |
mx=$(dig mx +noall +answer +nocomments $domain | head -n 1 | grep -oP 'MX\s[0-9]+\s\K(.+)(?=\.)') | |
real_ip=$(ping -c 1 $mx | head -n 1 | grep -oP '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') | |
echo "The real IP from the MX '$(echo $mx)' is '$(echo $real_ip)'" | |
echo "\n" | |
done < $domain_files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment