#!/bin/bash #Get specific MX a A records #set -x # Below some parameters you like to change Jut change it to anything, or # comment it out. If it is set to 1, things are active. # ################# INFO=1x # Information at the beginning and clearing the screen # COUNTRY=1 # Checking of the country. See below for more info # COLOR=1 # Colors on or off ################# ############################################################################ # # # If you install GeoIP the checking of the country is done much faster and # # it will be more acurate if you do a monthly update. GeoIP can be down- # # loaded from http://www.maxmind.com/geoip/api/c.shtml an rpm is available # # on my site at http://houghi.org/Fun/GeoIP-1.3.10-1.i386.rpm # # # # Best install GeoIP as you will be able to use other things as well. If # # you have another solution, please let me know a houghi AT houghi.org # # # ############################################################################ ############################################################################ ## No need to change anything here below this point # ############################################################################ ############################################################################ VERSION=0.6 CALLER=`basename $0` #colors COLORS () { bold=`tput bold;tput setaf 4` off=`tput sgr0` red=`tput setaf 1` green=`tput setaf 2` yellow=`tput setaf 3` blue=`tput setaf 4` purple=`tput setaf 5` cyan=`tput setaf 6` white=`tput setaf 7` under=`tput smul` } if [ $COLOR = 1 ] then COLORS fi # How to use HELP () { echo "${bold}$CALLER${off} version $VERSION by ${purple}houghi${off} Looking up diferent domaininformation on ANY domain Script is now owned by the general public. NO copyrights here. USAGE: $CALLER <-hvnawmkr> [DOMAIN.TLD] WHERE: -h = help -v = version -n = nameservers -a = A records and CNAME -w = WWW records -m = MX records -k = Known A records -r = Reversed known servers If enabled, it also gives the country of the different IP adresses. Standard all parameters will be used. A combination of parameters is possible. DOMAIN ${under}must${off} be a FQDN, like example.com or example.co.uk. Using a subdomain like sub.example.com ${bold}might${off} work. If you do not like the information that comes at the beginning of each data output, just change ${blue}INFO=1${off} to ${blue}INFO=0${off} in the script. If there is a delay at the end, this is most likely due to the fact that the server that does the country detection is not working. You need to change ${blue}COUNTRY=1${off} to ${blue}COUNTRY=0${off} in the script. Color can be turned off as well by changin ${blue}COLOR=1${off} to ${blue}COLOR=0${off}. " exit 1 } #Test if there is a TLD eval QUERYY=\$$# TLDY=`echo $QUERYY | grep "\."` if [ -z $TLDY ] then HELP fi # What version are you running VERSION () { echo "$CALLER Version: $VERSION" echo "" HELP } #Country codes {{{ COUNTRY_CODES () { ad="Andorra, Principality of" ae="the United Arab Emirates" af="Afghanistan, Islamic State of" ag="Antigua and Barbuda" ai="Anguilla" al="Albania" am="Armenia" an="the Netherlands Antilles" ao="Angola" aq="Antarctica" ar="Argentina" arpa="the Old style Arpanet" as="American Samoa" at="Austria" au="Australia" aw="Aruba" az="Azerbaidjan" ba="Bosnia-Herzegovina" bb="Barbados" bd="Bangladesh" be="Belgium" bf="Burkina Faso" bg="Bulgaria" bh="Bahrain" bi="Burundi" bj="Benin" bm="Bermuda" bn="Brunei Darussalam" bo="Bolivia" br="Brazil" bs="the Bahamas" bt="Bhutan" bv="Bouvet Island" bw="Botswana" by="Belarus" bz="Belize" ca="Canada" cc="Cocos (Keeling) Islands" cf="the Central African Republic" cd="Congo, The Democratic Republic of the" cg="Congo" ch="Switzerland" ci="the Ivory Coast (Cote D'Ivoire)" ck="the Cook Islands" cl="Chile" cm="Cameroon" cn="China" co="Colombia" com="the Commercial area" cr="Costa Rica" cs="the Former Czechoslovakia" cu="Cuba" cv="Cape Verde" cx="the Christmas Island" cy="Cyprus" cz="Czech Republic" de="Germany" dj="Djibouti" dk="Denmark" dm="Dominica" do="the Dominican Republic" dz="Algeria" ec="Ecuador" edu="the Educational area" ee="Estonia" eg="Egypt" eh="Western Sahara" er="Eritrea" es="Spain" et="Ethiopia" fi="Finland" fj="Fiji" fk="the Falkland Islands" fm="Micronesia" fo="Faroe Islands" fr="France" fx="France (European Territory)" ga="Gabon" gb="Great Britain" gd="Grenada" ge="Georgia" gf="French Guyana" gh="Ghana" gi="Gibraltar" gl="Greenland" gm="Gambia" gn="Guinea" gov="the USA Government" gp="Guadeloupe (French)" gq="Equatorial Guinea" gr="Greece" gs="the S. Georgia & S. Sandwich Isls." gt="Guatemala" gu="Guam (USA)" gw="Guinea Bissau" gy="Guyana" hk="Hong Kong" hm="the Heard and McDonald Islands" hn="Honduras" hr="Croatia" ht="Haiti" hu="Hungary" id="Indonesia" ie="Ireland" il="Israel" in="India" int="the International area" io="the British Indian Ocean Territory" iq="Iraq" ir="Iran" is="Iceland" it="Italy" jm="Jamaica" jo="Jordan" jp="Japan" ke="Kenya" kg="Kyrgyz Republic (Kyrgyzstan)" kh="Cambodia, Kingdom of" ki="Kiribati" km="Comoros" kn="Saint Kitts & Nevis Anguilla" kp="North Korea" kr="South Korea" kw="Kuwait" ky="Cayman Islands" kz="Kazakhstan" la="Laos" lb="Lebanon" lc="Saint Lucia" li="Liechtenstein" lk="Sri Lanka" lr="Liberia" ls="Lesotho" lt="Lithuania" lu="Luxembourg" lv="Latvia" ly="Libya" ma="Morocco" mc="Monaco" md="Moldavia" mg="Madagascar" mh="Marshall Islands" mil="USA Military" mk="Macedonia" ml="Mali" mm="Myanmar" mn="Mongolia" mo="Macau" mp="the Northern Mariana Islands" mq="Martinique (French)" mr="Mauritania" ms="Montserrat" mt="Malta" mu="Mauritius" mv="Maldives" mw="Malawi" mx="Mexico" my="Malaysia" mz="Mozambique" na="Namibia" nato="the NATO (this was purged in 1996 - see hq.nato.int)" nc="New Caledonia (French)" ne="Niger" net="the Network area" nf="the Norfolk Island" ng="Nigeria" ni="Nicaragua" nl="the Netherlands" no="Norway" np="Nepal" nr="Nauru" nt="the Neutral Zone" nu="Niue" nz="New Zealand" om="Oman" org="the Non-Profit Making Organisations area (sic)" pa="Panama" pe="Peru" pf="Polynesia (French)" pg="Papua New Guinea" ph="the Philippines" pk="Pakistan" pl="Poland" pm="Saint Pierre and Miquelon" pn="Pitcairn Island" pr="Puerto Rico" pt="Portugal" pw="Palau" py="Paraguay" qa="Qatar" re="Reunion (French)" ro="Romania" ru="the Russian Federation" rw="Rwanda" sa="Saudi Arabia" sb="Solomon Islands" sc="Seychelles" sd="Sudan" se="Sweden" sg="Singapore" sh="Saint Helena" si="Slovenia" sj="Svalbard and Jan Mayen Islands" sk="the Slovak Republic" sl="Sierra Leone" sm="San Marino" sn="Senegal" so="Somalia" sr="Suriname" st="Saint Tome (Sao Tome) and Principe" su="the Former USSR" sv="El Salvador" sy="Syria" sz="Swaziland" tc="the Turks and Caicos Islands" td="Chad" tf="the French Southern Territories" tg="Togo" th="Thailand" tj="Tadjikistan" tk="Tokelau" tm="Turkmenistan" tn="Tunisia" to="Tonga" tp="East Timor" tr="Turkey" tt="Trinidad and Tobago" tv="Tuvalu" tw="Taiwan" tz="Tanzania" ua="Ukraine" ug="Uganda" uk="the United Kingdom" um="the USA Minor Outlying Islands" us="the United States" uy="Uruguay" uz="Uzbekistan" va="the Holy See (Vatican City State)" vc="Saint Vincent & Grenadines" ve="Venezuela" vg="the Virgin Islands (British)" vi="the Virgin Islands (USA)" vn="Vietnam" vu="Vanuatu" wf="the Wallis and Futuna Islands" ws="Samoa" ye="Yemen" yt="Mayotte" yu="Yugoslavia" za="South Africa" zm="Zambia" zr="Zaire" zw="Zimbabwe" } #}}} # Get all the data online VARIABLES () { QUERY=$QUERYY #QUERY=`echo "$2" | tr '[A-Z]' '[a-z]'` QUERY=`echo "$QUERY" | tr '[A-Z]' '[a-z]'` # Top Level Domain TLD=`echo $QUERY | sed 's/^.*\.\([^\.]*\)$/\1/'` # Toplevel root ROOTDOM=`dig soa $QUERY |grep -v ';'|grep NS|sort|uniq|awk '{ print $5 }'|head -n 1` # Domain server SOADOMAIN=$ROOTDOM # Nameservers SOADOMAINS=`dig soa $QUERY @$ROOTDOM|grep -v ';'|grep NS|sort|uniq|awk '{ print $5 }'` # A records and C names #ARECORD=`dig a $QUERY @$SOADOMAIN|awk '/[^;]/ { if ($4 == "A") { print $0 } }'|grep $QUERY` #CRECORD=`dig a $QUERY @$SOADOMAIN|awk '/[^;]/ { if ($4 == "CNAME") { print $0 } }'` # WWW record #WWWRECORD=`dig a www.$QUERY @$SOADOMAIN |grep -i -A 4 'ANSWER'|grep A|grep -v ';'` #Finding MX record #MXRECORD=`dig mx $QUERY @$SOADOMAIN| awk '/[^;]/ { if ($4 == "MX") { print $0 } }'` # Some A records AARECORD=`dig any $QUERY @$SOADOMAIN|awk '/[^;]/ { if ($4 == "A") { print $0 } }'` # Reversed IP adress #REVERSED=`echo "$AARECORD"|awk '{print $5}'|sort|uniq` } #Beginning of the text STARTING () { if [ $INFO = 1 ] then echo "This can take a while. Please be patient. It ${bold}IS${off} working" echo "If you see problems or errors, please send them to houghi@houghi.org," echo "or or solve them yourself." echo "" fi } # The nameserver that is used START_2 () { echo "Information on ${blue}$QUERY${off} with ${yellow}$SOADOMAIN${off} as primary nameserver:" } # Nameservers NAME_SERVERS () { echo "" echo "${under}Primary and secondary${off} nameservers : " if [ -z "$SOADOMAINS" ] then echo "Only ${bold}$ROOTDOM${off} found. Please leave out the first part of ${bold}$QUERY${off}." fi if [ "$SOADOMAINS" ] then echo "$SOADOMAINS" fi } # A records and C names A_RECORDS () { ARECORD=`dig a $QUERY @$SOADOMAIN|awk '/[^;]/ { if ($4 == "A") { print $0 } }'|grep $QUERY` CRECORD=`dig a $QUERY @$SOADOMAIN|awk '/[^;]/ { if ($4 == "CNAME") { print $0 } }'` echo "" echo "${under}A record and CNAME:${off}" if [ -z "$ARECORD" ] then echo "No A records found for ${bold}$QUERY${off} on ${yellow}$SOADOMAIN${off}" fi if [ "$ARECORD" ] then echo "$ARECORD" fi if [ "$CRECORD" ] then echo "$CRECORD" fi } # WWW record WWW_RECORDS () { WWWRECORD=`dig a www.$QUERY @$SOADOMAIN |grep -i -A 4 'ANSWER'|grep A|grep -v ';'` if [ "$WWWRECORD" ] then if [ -z $A ] then echo "" fi echo "Record for ${blue}www.$QUERY${off}:" echo "$WWWRECORD" fi } #Finding MX record MX_RECORDS () { MXRECORD=`dig mx $QUERY @$SOADOMAIN| awk '/[^;]/ { if ($4 == "MX") { print $0 } }'` if [ "$MXRECORD" ] then echo "" echo "${under}MX record${off} for ${blue}$QUERY${off}:" echo "$MXRECORD" fi } #Info on the A records KNOWN_A_RECORDS () { if [ -z "$AARECORD" ] then echo "" echo "No A records found for ${bold}$QUERY${off} on ${yellow}$SOADOMAIN${off}" fi if [ "$AARECORD" ] then echo "" echo "${under}Known A records${off} for ${blue}$QUERY${off} on ${yellow}$SOADOMAIN${off}" echo "$AARECORD" fi } # Check if GeoIP is installed GEO_IP_ON () { GEO_IP=`whereis geoiplookup|awk '{print $2}'` if [ -z "$GEO_IP" ] then GEO_IP_Y=1 else if [ $INFO = 1 ] then echo "${green}For faster results, install GeoIP. See $CALLER code for more info.${off}" fi fi } #Look up the country name COUNTRY_NAME () { if [ -z $GEO_IP_Y ] then # Use GeoIP C_CODE=`geoiplookup $IP|awk -F", " '{print $2}'` COUNTRY_CODE="and is in ${purple}$C_CODE${off} ." #Exta space else # Use Online questioning COUNTRY_CODES # Test if the country must be looked up and if so, look it up # Tp disable this, just make COUNTRY not 1 at the beginning of the script if [ $COUNTRY = "1" ] then REVERSED_IP=`dig -x $IP|grep PTR|grep ";"|awk -F.in-addr '{print $1}'|awk -F";" '{print $2}'` COUNTRY_CODE=`dig a $REVERSED_IP.zz.countries.nerd.dk @ufo.hestdesign.com.|grep "IN CNAME"|awk -Fzz '{print $3}'|awk -F. '{print $1}'` # 100 free lookups per day # COUNTRY_CODE=`lynx -dump -accept_all_cookies "http://www.showmyip.com/simple/?ip=$IP&get=country"|grep -v Lookups` # If there is no country code, make that known. eval C_CODE=\$$COUNTRY_CODE if [ -z $COUNTRY_CODE ] then C_CODE="an unknown place" fi COUNTRY_CODE="and is in ${purple}$C_CODE${off}." fi fi } # Are there any reversed settings? REVERSED_SERVERS () { COUNTRY_CODES echo "" if [ $COUNTRY = 1 ] then if [ $INFO = 1 ] then echo "${green}If this is slow. Change COUNTRY in the source${off}" fi fi REVERSED=`echo "$AARECORD"|awk '{print $5}'|sort|uniq` if [ -z "$REVERSED" ] then echo "" echo "No A reversed found for ${bold}$QUERY${off} on ${yellow}$SOADOMAIN${off}" fi for IP in $REVERSED do COUNTRY_NAME echo "${under}Reversed${off} for ${blue}$IP${off} $COUNTRY_CODE" REV_IP=`dig -x $IP|grep PTR|grep -v ";"` if [ -n "$REV_IP" ] then echo $REV_IP fi done } # Parameter testing # Are ther any parameters if [ $1 = $QUERYY ] then A=1 #See that the layout is nice GEO_IP_ON VARIABLES STARTING START_2 NAME_SERVERS A_RECORDS WWW_RECORDS MX_RECORDS KNOWN_A_RECORDS REVERSED_SERVERS echo "" exit fi # Test the parameters PARAMETER=`getopt -o hvnawmkr -n $CALLER -- "$@"` if [ $? != 0 ] then echo "Terminating..." >&2 HELP exit 1 fi eval set -- "$PARAMETER" while true do case "$1" in -h) HELP ;; -v) VERSION ;; -n) N=NAME_SERVERS ; shift ;; -a) A=A_RECORDS ; shift ;; -w) W=WWW_RECORDS ; shift ;; -m) M=MX_RECORDS; shift ;; -k) K=KNOWN_A_RECORDS ; shift ;; -r) R=REVERSED_SERVERS; shift ;; --) shift ; break ;; *) echo "Internal error!" ; exit 1 ;; esac done #Running the script GEO_IP_ON VARIABLES STARTING START_2 $N; $A; $W; $M; $K ;$R echo "" #end of all exit