I'm not sure that you can do it the way you're trying to do it. I could be
wrong.
I actually just wrote code to do this last night, though, using WMI. I'm not
sure if this is the "best" way, but it seems to work. You can also do it
through unmanaged code, but I prefer to stick with managed code wherever
possible.
A few notes about the code below. The NetworkAdapter class simply stores the
IP address list, description, and MAC Address properties. You can save
whatever information you'd like. Search the MSDN for
Win32_NetworkAdapterConfiguration to see the available data. My code only
returns adapters that have IP addresses assigned to them.
My code is as follows:
public NetworkAdapterVector GetAdapterList()
{
ManagementClass mgmt = new
ManagementClass("Win32_NetworkAdapterConfiguration ");
ManagementObjectCollection moc = mgmt.GetInstances();
NetworkAdapterVector adapters = new NetworkAdapterVector();
// Search for adapters with IP addresses
foreach(ManagementObject mob in moc)
{
string[] addresses = (string[])mob.Properties["IPAddress"].Value;
if (null == addresses)
{
continue;
}
NetworkAdapter na = new NetworkAdapter();
na.Description = (string) mob.Properties["Description"].Value;
na.MacAddress = (string) mob.Properties["MACAddress"].Value;
na.IPAddresses = addresses;
adapters.Add(na);
}
return adapters;
}
--
http://www.petedavis.net
"HiChetu" <go**********@gawab.com> wrote in message
news:d4**************************@posting.google.c om...
I have a host which has two NIC cards; one configured for LAN
connections, and another for external connections.
Say the ip address are
1) x.x.x.x - for LAN
2) y.y.y.y - for external
hostname = 'hichetu'
With the following code snippet...
public void TestDNS(string hostname)
{
try
{
IPHostEntry hostInfo = Dns.Resolve(hostname);
IPAddress[] address = hostInfo.AddressList;
Console.WriteLine("Host name : " + hostInfo.HostName);
Console.WriteLine("\nIP Address list :");
for(int index=0; index < address.Length; index++)
{
Console.WriteLine(address[index]);
}
}
}
...I always get
Host name : hichetu.a.b
IP Address list
x.x.x.x
Now, How do i get the other ip address y.y.y.y ?