Solved

Get IP Address of remote computer

Posted on 2003-11-19
7
55,779 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:Maritimer
[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
7 Comments
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9779147
gethostbyname
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  
);
Parameters
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.

0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9779217
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9779224
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9779284
0
 

Accepted Solution

by:
ezicoder earned 50 total points
ID: 9785376
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;
HOSTENT *pHP;
SOCKADDR_IN myaddr;
myaddr.sin_family = AF_INET;

if ( SOCKET_ERROR != WSAStartup(0x202,&wsaData) )
{
     pHP = gethostbyname("www.google.com");
     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);
     WSACleanup();
}

Good Luck
0
 
LVL 1

Expert Comment

by:GavinThornton
ID: 9789575
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.

e.g.

struct sockaddr_in      sRecvSAddr;
int iRecvSize;

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


......... if you're using CSocket or something else, just look for the sockaddr_in structure.
0
 

Author Comment

by:Maritimer
ID: 9833611
Sorry I took so long.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

627 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