Operating System - HP-UX
1832438 Members
4590 Online
110042 Solutions
New Discussion

hosts list with DNS (in C)

 
Stefan Paitoni
Advisor

hosts list with DNS (in C)

Is there a way to get the complete list of the hosts known by the system, when the system uses DNS. Our network administrator recently reconfigured our network (to use DNS); I was using gethostent() to obtain the hosts list but now it does not work anymore. gethostent() man page says that the function gethostent() returns NULL with DNS, so what should I use ???
7 REPLIES 7
Jeff Schussele
Honored Contributor

Re: hosts list with DNS (in C)

Hi Stefan,


You can use the
gethostbyname
gethostbyaddr
functions.
You can use the nsquery function to determine which name service returned the data from above functions

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Stefan Paitoni
Advisor

Re: hosts list with DNS (in C)

gethostbyname() and gethostbyaddr() returns infos from a specified host name. What I want is a complete list, without specifying host name, using a loop (while...)
Gregory Fruth
Esteemed Contributor

Re: hosts list with DNS (in C)

When using DNS, all hosts on the Internet are known
to your system. You do NOT want to list them all!

Perhaps you just want to enumerate the hosts in
your DNS domain (".mycompany.com" or whatever),
or on your LAN. I don't know how to do the former.
The latter should be relatively easy to do, but your
network admin will probably not be very happy with
it.
Stefan Paitoni
Advisor

Re: hosts list with DNS (in C)

yes you are right (i am sorry, I was not accurate enough describing my problem). I only need the hosts configured in our DNS domain. There should be a function to do that.
Gregory Fruth
Esteemed Contributor

Re: hosts list with DNS (in C)

Perhaps a DNS expert can suggest otherwise, but I think
you're going to have to speak directly to DNS server.
See the man pages for resolver(4), resolver(3N), named(1m),
and the appropriate RFCs.

On the other hand, it appears that the nslookup command
is able to do what you want. Perhaps you can
system("nslookup ...") and parse the results, or maybe
you can get the source code for the GNU version and see
how they do it.

Example:

unix% nslookup
Default Name Server: dns.mycompany.com
Address: 123.456.789.1

> ls mycompany.com

foo 123.456.789.2
bar 123.456.789.3
baz 123.456.789.4
quux 123.456.789.5
etc.

Good luck!
Sanjay_6
Honored Contributor

Re: hosts list with DNS (in C)

Hi,

I have an application calles hummingbird exceed on my workstation. There is a utility that comes with this application. The utility is called nslookup. This utility can be configured to do nslookup using a dns server. There is an option to get the list of all the hosts configured into the DNS for a particular domain.

This is a licenced application and is a $$$ product.

http://www.hummingbird.com/products/nc/exceed/

Hope this helps.

Regds
Helen French
Honored Contributor

Re: hosts list with DNS (in C)

One way to get the list, although not programmatically is to use nslookup and do a dump of the database.

For example :

> ls -t sub.rose.hp.com
[dyna.sub.rose.hp.com]
$ORIGIN sub.rose.hp.com.
burfurd 1D IN A 192.168.20.85
dyna 1D IN A 192.168.20.5
gateway 1D IN A 192.168.20.1
localhost 1D IN A 127.0.0.1
moo 1D IN A 192.168.20.86

Of course, this pre-supposes you know the domain you want to dump.

If you want to do it programmatically, try posting Mr DNS at http://www.acmebw.com. Cricket and some old hp hostmasters still hang out there, and are very helpful. There is even a searchable database.
Life is a promise, fulfill it!