From: Maanu on
Hi,

How can I get the IP address of a network card in my machine? I have the
NetworkInterface object corresponding to that card

Thanks!

From: Matt on
On Jun 15, 6:20 am, Maanu <Ma...(a)discussions.microsoft.com> wrote:
> Hi,
>
> How can I get the IP address of a network card in my machine? I have the
> NetworkInterface object corresponding to that card
>
> Thanks!

http://www.codeguru.com/csharp/csharp/cs_network/article.php/c6041

Matt
From: Arne Vajhøj on
On 15-06-2010 08:20, Maanu wrote:
> How can I get the IP address of a network card in my machine? I have the
> NetworkInterface object corresponding to that card

Some old code from the shelf:

using System;
using System.Net.NetworkInformation;

namespace EE
{
public class MainClass
{
public static void Main(string[] args)
{
NetworkInterface[] nics =
NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface nic in nics)
{
if(nic.GetPhysicalAddress().ToString().Length > 0 &&
nic.GetIPProperties().UnicastAddresses.Count > 0)
{
Console.WriteLine(nic.GetPhysicalAddress() + " " +
nic.GetIPProperties().UnicastAddresses[0].Address);
}
}
}
}
}

Arne
From: ksrao via DotNetMonster.com on
Hi,
Let me explain you what is IP address and MAC adress. IP address is a
logical address which is in 32 bit given by either manuallyor by the system
administrator or through DHCP dynamically. MAC address is a physical address
which is in 48 bits. It is given by the manufacturer and that can not be
changed and it is in permanent in nature.

When assign a IP Address this address will map to the MAC address, Now the
logic is that as you are knowing MAC just you have to pick up IP.

See in case of Virtual LAN one NIC may ge assigned with more than one IP.
Then whic IP is active that IP Address you will get.


>using System;
>using System.Net.NetworkInformation;
>
>namespace EE
>{
> public class MainClass
> {
> public static void Main(string[] args)
> {
> NetworkInterface[] nics =
>NetworkInterface.GetAllNetworkInterfaces();
> foreach(NetworkInterface nic in nics)
> {
> if(nic.GetPhysicalAddress().ToString().Length > 0 &&
> nic.GetIPProperties().UnicastAddresses.Count > 0)
> {
> Console.WriteLine(nic.GetPhysicalAddress() + " " +
>nic.GetIPProperties().UnicastAddresses[0].Address);
> }
> }
> }
> }
>}
>

For more C# Tests click on http://www.wiziq.com/tests/c

--
Message posted via http://www.dotnetmonster.com

From: Arne Vajhøj on
On 16-06-2010 10:45, ksrao via DotNetMonster.com wrote:
> Let me explain you what is IP address and MAC adress.

My guess is that everybody here knows, so why explain it
when nobody asked.

Arne