Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get all IP Addresses for a host from DNS server?

Status
Not open for further replies.

atulnandan

Programmer
May 24, 2011
1
US
I have a program for which the purpose is to find all IP addresses associated with a host in a particular domain. For example, let's say that i want to find all IP addresses associated with "rediff.com". If i do "nslookup" on rediff.com, i get different set of IP addresses at different point of time as follows:


atul> nslookup rediff.com
Server: ns.otherdnserver.org
Address: 10.12.35.8

Non-authoritative answer:
Name: rediff.com
Address: 64.212.198.153
Name: rediff.com
Address: 64.212.198.144



atul> nslookup rediff.com
Server: ns.otherdnserver.org
Address: 10.12.35.8

Non-authoritative answer:
Name: rediff.com
Address: 168.143.241.10
Name: rediff.com
Address: 168.143.241.90


Same behaviour is observed with gethostbyname() api utility which my program is calling and i am getting different subset of IP addresses at different point of time.

Is there a way where i can invoke gethostbyname() with a hostname with certain specific option and it returns me all IP addresses associated with it in one invocation, not in multiple
invocations as mentioned in the above example?
 
Try dig. For example: dig any rediff.com gives the following:

Code:
; <<>> DiG 9.4-ESV-R4 <<>> any rediff.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29815
;; flags: qr rd ra; QUERY: 1, ANSWER: 12, AUTHORITY: 8, ADDITIONAL: 4

;; QUESTION SECTION:
;rediff.com.                    IN      ANY

;; ANSWER SECTION:
rediff.com.             1800    IN      MX      10 mx.rediffmail.rediff.akadns.net.
rediff.com.             1800    IN      SOA     ns1.rediff.com. webmaster.rediff.co.in. 2011051802 86400 7200 3628800 1800
rediff.com.             300     IN      A       202.137.237.21
rediff.com.             300     IN      A       202.137.236.33
rediff.com.             1800    IN      NS      usc2.akam.net.
rediff.com.             1800    IN      NS      ns1-225.akam.net.
rediff.com.             1800    IN      NS      eur4.akam.net.
rediff.com.             1800    IN      NS      use9.akam.net.
rediff.com.             1800    IN      NS      ns1-245.akam.net.
rediff.com.             1800    IN      NS      eur1.akam.net.
rediff.com.             1800    IN      NS      asia2.akam.net.
rediff.com.             1800    IN      NS      use4.akam.net.

;; AUTHORITY SECTION:
rediff.com.             1800    IN      NS      use9.akam.net.
rediff.com.             1800    IN      NS      eur1.akam.net.
rediff.com.             1800    IN      NS      ns1-245.akam.net.
rediff.com.             1800    IN      NS      usc2.akam.net.
rediff.com.             1800    IN      NS      asia2.akam.net.
rediff.com.             1800    IN      NS      eur4.akam.net.
rediff.com.             1800    IN      NS      use4.akam.net.
rediff.com.             1800    IN      NS      ns1-225.akam.net.

;; ADDITIONAL SECTION:
mx.rediffmail.rediff.akadns.net. 58 IN  A       119.252.147.10
eur1.akam.net.          77215   IN      A       213.155.153.132
eur4.akam.net.          3097    IN      A       213.155.153.132
usc2.akam.net.          3079    IN      A       64.215.164.170

;; Query time: 84 msec
;; SERVER: 152.19.240.8#53(152.19.240.8)
;; WHEN: Tue May 24 10:23:09 2011
;; MSG SIZE  rcvd: 509
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top