Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hallo, Does anyone know a Visual

Status
Not open for further replies.

Frink

Programmer
Mar 16, 2001
798
GB
Hallo,

Does anyone know a Visual C++ function to return the TCP/IP properties of the local machine?
I mean the IP Address and/or Default Gateway.

I've used gethostbyname as a way around it but that returns the 127.0.0.1 address on Windows 2000 if there is no network connected, whereas I need the actual IP address set up in the TCP/IP properties

Any help much appreciated,

- Frink
 
If theres no network connected, I wouldn't be at all surprised if whatever you did resulted in the local loopback address.

It must be stored somewhere, try the registry ?

K
 
To obtain the IP address using socket library functions performs a reverse DNS lookup. Therefore you need a connection to get anything other than the loopback address.

If the machine is using DHCP then it does not even have an IP when disconnected. If it is using a fixed IP then I suppose the IP is stored somewhere. Let us know if you find it.


-pete
 
On a Unix Machine TCP/IP addresses will be stored in the Hosts file, so look for that I suppose, then if you havea fixed IP, you could read it from the file.

If you have a console ap, you could use ipconfig.exe

But all of this is useless if, as pete said you are on DHCP, as then your IP is only assigned by your PDC / ISP when you connect.

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top