IP Address of Network interface Card

M

Maanu

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!
 
A

Arne Vajhøj

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top