I'm programming a little software dealing with the IP configuration of my
computer. I've spent two weeks digging in the IP-helper doc and I can't find
a simple way to get my complete IP configuration.
I've tried to use GetAdaptersAddresses but I miss some informations like the
subnet masks and the gateways associated to each interface.
So my second shot was GetAdaptersInfo. But for an interface that uses a DHCP
server, I get no information about its IP configuration, the IpAddressList is
empty...
I just want to get the following informations for every interface connected
to my computer :
- does it use a DHCP server?
- what are the IP adresses, subnet masks and gateways associated to this
interface, even if this configuration has been given by a DHCP server?
Any suggestions would be greatly appreciated.
Thank you in advance,
Djibi
That shouldn't happen. This API works fine and returns correct info for DHCP
assigned addresses. I suspect there is a bug in your code so try to compile
the MSDN sample from GetAdaptersInfo and see what it shows.
--
Eugene
http://www.gershnik.com
"Eugene Gershnik" wrote:
> Djibi wrote:
> > So my second shot was GetAdaptersInfo. But for an interface that uses
> > a DHCP server, I get no information about its IP configuration, the
> > IpAddressList is empty...
>
> That shouldn't happen. This API works fine and returns correct info for DHCP
> assigned addresses.
This is good news.
> I suspect there is a bug in your code so try to compile the MSDN sample
> from GetAdaptersInfo and see what it shows.
Well, in fact, this is what I did. But I'm programming in C#, so I've
adapted the example to the language. I'm going to check it again but I think
everything's fine since I get IP addresses for interfaces with fixed IP
addresses.
One more question : is it possible to get the IP configuration for an
adapter that is in status IfOperStatusDown? When I go in the IP settings of
the interface, I can see them. But when I use the API, I have the same IP
address as the one given by ipconfig utility in such a case : 0.0.0.0 ...
Why do you bother with adapting? Write the relevant part in Managed C++ (or
C++/CLI if you got VC 8) exactly as it is in MSDN and call it from the rest
of C# code.
> One more question : is it possible to get the IP configuration for an
> adapter that is in status IfOperStatusDown? When I go in the IP
> settings of the interface, I can see them. But when I use the API, I
> have the same IP address as the one given by ipconfig utility in such
> a case : 0.0.0.0 ...
Well APIs usually are geared toward "show what the state is now" rather than
"show what user wants the state to be". You can try to see if WMI is able to
get this info. If not reading the registry directly is the only option.
--
Eugene
http://www.gershnik.com