Solved

Internet Address To IP Address

Posted on 2004-09-10
4
342 Views
Last Modified: 2010-04-01
Is there a way I can get the IP address from an internet address usinging Winsocks.  I.E.  

Input
www.abc.com

Output
111.111.111.111
0
Comment
Question by:kipp8r
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 12030573
The gethostbyname subroutine retrieves host address and name information using a host name as a search key.
0
 
LVL 30

Accepted Solution

by:
Axter earned 200 total points
ID: 12030598
char acClientHost[255];
WORD wVersionRequested;
WSADATA wsaData;
struct hostent *pHostent = NULL;
 
wVersionRequested = MAKEWORD( 1, 1);

if ( nErr = WSAStartup ( wVersionRequested, &wsaData))
{
  // error initializing winsck...
}

    if  (   dwErr =   gethostname (   ( char *) acClientHost, 255))
        {
            return  (   nWSockRC);
        }

if (!(pHostent = gethostbyname ( acClientHost)))
{
 // an error occured...
}
else
{
 printf ( "IP: %s\n", BinIP2StrIP ( *(( long *)  pHostent->h_addr));
}


char *BinIP2StrIP ( long lnIP)
{
static char s_acStrIP [ 16];

PUCHAR puc = ( unsigned char *) &lnIP;
unsigned int aun [ 4];

for ( int i = 0; i < 4; aun [ i++] = *puc++);

sprintf ( s_acStrIP, "%d.%d.%d.%d", aun [ 0], aun [ 1], aun [ 2], aun [ 3]);

return ( s_acStrIP);
}
0
 
LVL 30

Expert Comment

by:Axter
ID: 12030623
Above code was copied and pasted from following link:
http:Q_10167656.html

See also following links:
http:Q_10035481.html
http:Q_20063911.html
0
 

Author Comment

by:kipp8r
ID: 12049751
Thank You Axter!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

726 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