[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Internet Address To IP Address

Posted on 2004-09-10
4
Medium Priority
?
348 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 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

656 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