Archived

This topic is now archived and is closed to further replies.

Prozak

Sockets: Retrieving my IP

Recommended Posts

Shannon Barber    1681
quote:
Original post by pentium3id
And what call should one make to know if the machine is
connected to internet/intranet ?


Do you mean like is the modem connected? I think you can determine that, I think it''s buried in the TAPI for Windows.

If you mean, does this computer have an ip route to Internet? Then you have to do something underhanded, like ping a known internet server... or tracert to your website.


Magmai Kai Holmlor

"Oh, like you''ve never written buggy code" - Lee

"What I see is a system that _could do anything - but currently does nothing !" - Anonymous CEO

Share this post


Link to post
Share on other sites
JonStelly    127
Look into the IP Helper API. Specifically, the GetIpAddrTable() function to get your valid IP addresses, and GetIfTable to get the status for each given interface.

Share this post


Link to post
Share on other sites
barazor    122
heres some code that gets your local ip address:

    

#include <winsock.h>


#include <iostream.h>

main()
{
hostent* localInfo = gethostbyname(NULL); // get localhost name

in_addr addr;
memcpy(&addr,localInfo->h_addr_list[0],sizeof(in_addr));
cout << inet_ntoa(addr) << endl;
}


Edited by - barazor on December 30, 2001 12:46:01 AM

Share this post


Link to post
Share on other sites