Thread: Dns!!!

  1. #1
    Shakespeare3335
    Guest

    Dns!!!

    Hi guys,

    How can i input an ip address and then do a dns lookup to get the hostname.

    I don't want the code just a general pointer in the right direction

    Thanks a lot.

    Shakespeare

  2. #2
    Registered User devil@work's Avatar
    Join Date
    Mar 2003
    Posts
    33
    read beej guide to network programming small and easy to understand. google will return in in the first place

  3. #3
    Shakespeare3335
    Guest
    Hi guys,

    thanks for the replies, unfortunately it isn't exactly what i want. Here is what i have:

    Code:
    #include <winsock.h>
    #include <iostream>
    using namespace std;    
    
    int main()
    {
    
    	struct hostent *h;
    
    	WSADATA wsaData;
    
                    if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
                          fprintf(stderr, "WSAStartup failed.\n");
                    exit(1); }
    	
    	h = gethostbyname("www.yahoo.com"); 
    
    	cout << "Official Host Name: " << h->h_name << endl ;
    	cout <<"IP Address : " <<  inet_ntoa(*((struct in_addr *)h->h_addr)) << endl ;
    
    	return 0 ;
    }
    What i have is the ability to input a domain name and get the IP address. BUT..what i want is to be able to input an ip address and get back the domain name.

    Unfortunately i have been unable to modify my code to acheive this.

    Anyone know how i could get round this.

    Thanks a lot

  4. #4
    Shakespeare3335
    Guest
    OK heres what i have

    [CODE]

    #include <winsock.h>
    #include <iostream>
    using namespace std;

    int main()
    {

    struct hostent *h;
    char ip[64] = "212.113.202.50";
    unsigned int addr;

    addr = inet_addr(ip);

    WSADATA wsaData;

    if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
    fprintf(stderr, "WSAStartup failed.\n");
    exit(1);
    }

    cout << "IP address is: " << ip << endl ;

    h = gethostbyaddr((char *)&addr,12,AF_INET);

    if (h == NULL)
    {
    cout << "Cannont resolve address: " << ip << endl ;
    }
    else
    cout << "Official Host Name: " << h->h_name << endl ;


    return 0 ;

    }

    /CODE]

    i can specify an ipaddress and it then outputs the host name, great, but what i actually wanted and didn't realise is i want the actual url of the ipaddress.

    Is this possible.

    I mean i pinged say www.yahoo.com to get the ipaddress:
    216.109.125.69

    but when i then use this in my program to test it returns:
    w16.www.dcn.yahoo.com

    which is not www.yahoo.com, which is what i wanted.

    How can i get it to output the correct url? or isn't it possible?

    cheers guys

  5. #5
    Shakespeare3335
    Guest
    Code:
    #include <winsock.h>
    #include <iostream>
    using namespace std; 
    
    int main()
    {
    
    struct hostent *h;
    char ip[64] = "212.113.202.50";
    unsigned int addr;
    
    addr = inet_addr(ip);
    
    WSADATA wsaData;
    
    if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
    fprintf(stderr, "WSAStartup failed.\n");
    exit(1);
    }
    
    cout << "IP address is: " << ip << endl ;
    
    h = gethostbyaddr((char *)&addr,12,AF_INET); 
    
    if (h == NULL)
    {
    cout << "Cannont resolve address: " << ip << endl ;
    }
    else
    cout << "Official Host Name: " << h->h_name << endl ;
    
    
    return 0 ;
    
    }

  6. #6
    Shakespeare3335
    Guest
    OK vVv,

    I did read that post but you obviously didn't read mine.

    I succesfully managed to get the hostname for a given IP address, and this was thanks to your link that i was able to do this.

    So did i bother to read your post, yes, actually from start to finish which took quite some time. Also it was very interesting you obvously know your stuff.

    and yes your correct that it contained IP to DNS and DNS to IP.

    what I was SAYING is that i pinged say, www.yahoo.com and obtained the ip address for it.
    I then used my program to translate it back into its hostname, which was successsful but did not come back with www.yahoo.com like i had HOPED. it came back with w5.dcx.yahoo.com.

    you see all i was saying, and maybe i wasn't clear, is that i don't want the server the site is hosted on, i want the site itself. although i read my post and it seems clear to me.

    Now what i am doing is an program which monitors which sites have been accessed and at what times and stuff and for this i need the actual site not the server. Since the yahoo site returned a yahoo server not all sites are hosted on servers that have there name in the server name.

    So why should you bother to help me, you shouldn't, i don't need help from people like you, and although i'm not a good programmer yet i will be, you are a good programmer but you will also always be a prick.

    once again nice FAQ, your the man.

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    64
    >No need for strong feelings. It was a misunderstanding, OK?
    Hey no problem, i don't hold grudges. Your name is vVv right i'll write that down. (only kidding)

    >That post contains the same question as your original post >using different words, but without any update, so it looked >pretty much like you didn't read the link I posted.
    ok, it was different though, i was saying that i was able to get DNS - IP, i was then asking how to get IP- DNS. (which your FAQ helped me with) Also i had posted what i had so far so it was easier for people to see i had actually done something and could maybe point out any mistakes i was making.

    > I then used my program to translate it back into its hostname,
    > which was successsful but did not come back with
    > www.yahoo.com like i had HOPED. it came back with
    > w5.dcx.yahoo.com.
    anyone know if this information will be anywhere on my servers, like in a log file or something.

    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Asynchronous DNS library (+ license)
    By EVOEx in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:03 PM
  2. DNS issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-02-2008, 10:15 AM
  3. DNS & Mail settings modifier
    By DemonSoul in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 05-20-2004, 12:43 PM
  4. dns server settings
    By impactBlue in forum Tech Board
    Replies: 0
    Last Post: 03-09-2004, 01:45 AM