I'm wondering how I'd go about getting the:
- Internal IP address;
- External IP address; and
- Default gateway
in Windows (WinSock) and Unix systems.
Thanks in advance,
I'm wondering how I'd go about getting the:
in Windows (WinSock) and Unix systems.
Thanks in advance,
There is no general purpose mechanism that works on Windows and UNIX. Under Windows you want to start with
GetIfTable()
. Under most UNIX systems, trygetifaddrs()
. Those will give you various things like the IP address of each interface.I'm not sure how one would go about getting the default gateway. I would guess that it is available via some invocation of
sysctl
. You might want to start with the source for the netstat utility.The external public address is something that a computer never knows. The only way is to connect to something on the internet and have it tell you what address you are coming from. This is one of the classic problems with IPNAT.
Linux:
Windows:
I'm not sure how to definitively determine the external ip in either system
Solved thanks to: http://www.codeguru.com/forum/showthread.php?t=233261