Solved

Internet Address To IP Address

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need some help with listview limit text 20 112
thread-safe code in c++ 2 116
Gaming Software 1 19
FMX TEdit KeyUp handler detecting  "enter" key 4 14
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

829 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