Solved

Internet Address To IP Address

Posted on 2004-09-10
4
315 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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.

863 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

21 Experts available now in Live!

Get 1:1 Help Now