+ Reply to Thread
Results 1 to 2 of 2

Thread: Getting ip address from domnain name

  1. #1

    Getting ip address from domnain name

    I am having issue with getting IP from domain name.

    How to get IP address from domain name?

    Is there any WIN32 API available for this?

    Thanks in advance.

  2. #2
    You can use gethostbyname for this purpose.

    EXample:

    Code:
    CString GetIPAddressFromDomainName(CString strDomainName)
    {
    	CString strIPAddress ;
    
    	WSADATA wsaData ;
    
    	WSAStartup(MAKEWORD(2, 2), &wsaData) ;
    
    
    	struct hostent *host = gethostbyname(strDomainName.GetBuffer(0)) ;
    
    	if (NULL != host) 
        {
    		struct in_addr addr ;
    		addr.s_addr = *(u_long *) host->h_addr_list[0] ;
            strIPAddress = inet_ntoa(addr) ;
    	}
    
    	WSACleanup() ;
    
    	return strIPAddress ;
    }
    
    CString strIPAddress = GetIPAddress("www.google.com") ;

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts