Get IP Address of remote computer

Currently I have an application that runs on our network. When someone logs on to the network it checks there system and gets the pc name. I would like to also get the IP address of that system. As well I may later like to ping that computer.

1) Is there a function to get the IP of this remote system?
2) IS the a function to ping a remote system and receive back the response?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The gethostbyname function retrieves host information corresponding to a host name from a host database.

Note  The gethostbyname function has been deprecated by the introduction of the getaddrinfo function. Developers creating Windows Sockets 2 applications are urged to use the getaddrinfo function instead of gethostbyname.

struct hostent FAR *gethostbyname(
  const char FAR *name  
[in] Pointer to the null-terminated name of the host to resolve.
Return Values
If no error occurs, gethostbyname returns a pointer to the hostent structure described above. Otherwise, it returns a NULL pointer and a specific error number can be retrieved by calling WSAGetLastError.

Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

remove "http" string from URL

#include <Winsock2.h>

// do't forget to add WS2_32.LIB

// in your function

char szHostName[256];
char szIpAddress[256];
WSADATA wsaData;
myaddr.sin_family = AF_INET;

if ( SOCKET_ERROR != WSAStartup(0x202,&wsaData) )
     pHP = gethostbyname("");
     memcpy((char FAR *)&(myaddr.sin_addr), pHP->h_addr, pHP->h_length);  
     wsprintf(szIpAddress,"%d.%d.%d.%d",myaddr.sin_addr.S_un.S_un_b.s_b1,myaddr.sin_addr.S_un.S_un_b.s_b2, myaddr.sin_addr.S_un.S_un_b.s_b3,myaddr.sin_addr.S_un.S_un_b.s_b4);

Good Luck

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Assuming your server app uses "SOCKET accept (  SOCKET s, struct sockaddr FAR* addr, int FAR* addrlen );" to accept connections from the clients you can get their ip address from the sockaddr.


struct sockaddr_in      sRecvSAddr;
int iRecvSize;

// iServerSocket is your listening socket
if( accept(iServerSocket, (struct sockaddr*)&sRecvSAddr, &iRecvSize) < 0 )
    unsigned int iIP = sServerConnectContainer.sRecvSAddr.sin_addr.s_addr;

......... if you're using CSocket or something else, just look for the sockaddr_in structure.
MaritimerAuthor Commented:
Sorry I took so long.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.