Simple:
It does not make the stupid assunmption that a ystem that normally is under
external control and may not show your data (the DNS used by your computer)
is actually up to date.
Especially customers using a dial up DNS connection may be surprised.
What the "original solution" (which is a typical "I don't care what reality
says, it works here") returned were NOT the IP addresses that the computer
had.
THe original solution did this:
* Get the name of the computer.
* Ask the DNS name service available for the computer for the IP Addresses
attached to this name.
The second step basically has VERY HIGH failure tolerance, especially in
non-professional environments and ISP scenarios.
The second solution (there is a third, using P/IVOKE to the IpHelper library
and just getting all ip addresses) was using WMI (Windows Management
Instrumentation) to actually ask the local NETWORK CARDS and the TCP IP
STACK bound to them for the addresses registered.
Technically this is a valid solution.
See it like a court case
The second solution was asking a witness what he knows about the case.
Legally valid - the network cards basically have to know what their IP
addresses are).
The first solution would be thrown out as hearsay - basically going out and
asking a stranger what he things about a topi in question. Becuase there is
no requirement that:
* There IS A DNS Server.
* The DNS Server is updated.
* The DNS Server contains the correct information.
and then your software suddenly fails, and basically you told the world you
are not knowing what you are doing. Interesting enough, as I said earlier,
this WILL fail often - basically all dialup internet IP addresses do not get
the host name updates (what the heck does the ISP care about the host name
you tend to enter into your computer?)
"It works here" is for me a reson to fire people. WHen people don#t to their
homwork and read the documentation but then tell ime it works on their
computer - they should server burgers ad McDonalds.
Reead documentation, guys.
When you are asked to return a list of local IP Addresses, do this. Do not
rely on undocumented behavior and assume it will just work.
And yes, btw - I HAVE seen cases (we still try to repro them) where I
actually did get an EXCEPTION on the initial query - with some ISP's at some
times.
Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)