Shell Script To Get Data Center Information, IP Owner, City and Country From Domain Name

Posted on in Categories Domain, Monitoring, Networking last updated March 12, 2010

Run script as follows:
./script.sh cyberciti.biz google.com
Sample outputs:

15 comment

  1. Good job, script works on MAC OSX/LION:

    Arvinds-MacBook-Pro:~ arvind$ arvindsMac/work/PDI-scripts/get-dns.sh 123
    Error: 123 is not valid domain or dns error.
    Arvinds-MacBook-Pro:~ arvind$
    Arvinds-MacBook-Pro:~ arvind$ arvindsMac/work/PDI-scripts/get-dns.sh google.com
    Getting information for domain: google.com [ 74.125.236.66 ]…
    NetRange: 74.125.0.0 – 74.125.255.255
    OriginAS:
    OrgName: Google Inc.
    City: Mountain View
    Country: US

    Arvinds-MacBook-Pro:~ arvind$
    Arvinds-MacBook-Pro:~ arvind$
    Arvinds-MacBook-Pro:~ arvind$ arvindsMac/work/PDI-scripts/get-dns.sh agoogle.com
    Getting information for domain: agoogle.com [ 216.65.41.185 ]…

    Arvinds-MacBook-Pro:~ arvind$
    Arvinds-MacBook-Pro:~ arvind$

  2. I tried using above script on CentOS 6 but the same is not working and giving error as

    ./searchdomain.sh google.co.in yahoo.co.in
    ./searchdomain.sh: line 22: host: command not found
    Error: google.co.in is not valid domain or dns error.
    ./searchdomain.sh: line 22: host: command not found
    Error: yahoo.co.in is not valid domain or dns error.
    Please advise

    1. Hi , i get the same as DeepakSharma , i was wondering does anyone know what this is about ? Im using Fedora 15 , 64bit .
      /e I tryed “whois” command but i dont have so i replaced it with “who” , maybe thats the reason? Any ideas in general ? :)

      1. The issue is because of the egrep command – currently its filtering the lines starting with OrgName:|City:|Country:|OriginAS:|NetRange:

        but .org .biz and some other TLDs use a bit different wording – try to change line:
        whois “$_ip” | egrep -w ‘OrgName:|City:|Country:|OriginAS:|NetRange:’

        with

        whois “$_ip” | egrep -w ‘OrgName:|City:|Country:|OriginAS:|NetRange:|inetnum|address|descr’

        at least that works good enough for me.

        Cheers,
        Stanimir

        1. How about this one? This fixed it on my centos 5.8 box:

  3. There is no need to use three programs if you can do it with one.

    should read

  4. – You should not use [ but [[
    – You should not use this as a valid test [ “$_ip” == “” ]
    but test the return value [[ $? -eq 0 ]]

Leave a Comment