Solved

DNS of a IPaddress

Posted on 2004-04-02
10
710 Views
Last Modified: 2010-04-15
How can i get the DNS name of a remote IP address?
0
Comment
Question by:aishwaria
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 57

Expert Comment

by:Pete Long
ID: 10740411
Hi aishwaria,
you need to query the whois database to get that info
Im dont know how to do that programatically but heres a php script that does the same
http://www.weberdev.com/get_example.php3/460

PeteL
0
 
LVL 57

Expert Comment

by:Pete Long
ID: 10740446
0
 

Author Comment

by:aishwaria
ID: 10740507
I need the C code which gets the DNS name.
0
 
LVL 45

Expert Comment

by:Kdo
ID: 10740835
Hi aishwaria,

There is quite a bit of coding involved to do what you want to do.  I suggest you follow Pete's links, or come up with another way to do this.

If you're on a *nix system you can always do this with a shell script.  In fact, even in a Windows world using the system tools to do the nslookup and writing a C program to examine the results might be the easiest.

nslookup <ip-address> | YourProgramToCheckAnswer


main ()
{
  /*  read stdin until end-of-file and examine the returned records  */
}



Good Luck,
Kent
0
 
LVL 57

Expert Comment

by:Pete Long
ID: 10741389
well I hope so, its probably the only chance I'll ever have of points in this TA LOL :)
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Expert Comment

by:ravenscr98
ID: 10746595
aishwaria:

Look at the "gethostbyaddr" and "gethostbyname" functions.  These functions query DNS for a given host name or IP address.  It sounds like you have a numeric IP address and want the corresponding hostname.  You will need to use "gethostbyaddr" and your program will have three steps.

1.  Fill in an in_addr structure with the IP address (or a in6_addr structure for IPv6).  You will need to use either "inet_aton" or "inet_pton" to convert the dotted string version, such as "1.23.34.45",  of the IP adddress and store it in the in_addr structure.  IPv6 must use the "inet_pton" function to convert and store the IPv6 address string.

2. Call "gethostbyaddr" function with the address of the in_addr or in6_addr structure as the first argument.  If the function succeeds, it will return the address of a hostent structure.

3. The h_name field of the hostent structure has the official hostname for the IP address.  The h_aliases field is a pointer to NULL terminated array of string pointers that list all aliases for the host.

Do a man on the functions to get more details.

Also, see "UNIX Network Programming," Volume 1 by W. Richard Stevens for a more complete discussion.  He includes a nice example that uses gethostbyname to get the IP addresses and aliases for a given hostname.

- rob r.
 
0
 
LVL 1

Accepted Solution

by:
ravenscr98 earned 25 total points
ID: 10746701
aishwaria:

Having posted my previous solution, I failed to mention that POSIX is now marking "gethostbyaddr" and "gethostbyname" as obsolescent.  The preferred solution is to use the "getaddrinfo" function.  You pass the dotted IP address string as the hostname argument and set the service argument to NULL.  You also have to fill in a hints structure.  The fourth argument is used to return a linked list of addrinfo structures.  You will find the hostname in the ai_canonname field of the addrinfo structure.
0
 

Author Comment

by:aishwaria
ID: 10746806
When i passed the the ip address 10.185.3.50 i got 10.185.3.96 as result.
I used getaddrinfo.
What is the mistake i had committed.
0
 

Author Comment

by:aishwaria
ID: 10746808
Sorry my result was,10.185.3.50.
I had typed it wrong
0
 

Author Comment

by:aishwaria
ID: 10747066
Hi rob

I am able to get the host name by using the getaddrinfo.
Thanks for the help.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert image to byte array 8 174
pgpool-II on Ubuntu 14.04... ARGH! 5 812
Trouble linking program with -lcrypt 3 133
C#, VS15, StructLayout 1 116
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now