Skip to content

Instantly share code, notes, and snippets.

@dhyegocalota
Created May 5, 2016 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhyegocalota/dd783fe9cf2918b027c1a39b08b523f3 to your computer and use it in GitHub Desktop.
Save dhyegocalota/dd783fe9cf2918b027c1a39b08b523f3 to your computer and use it in GitHub Desktop.
#!/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