Prev: my DrawImage doesn't draw when addes to the c-tor
Next: Urgent! C# Developer wanted in the Chicagoland area!
From: Maanu on 15 Jun 2010 08:20 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 15 Jun 2010 10:35 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 15 Jun 2010 21:57 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 16 Jun 2010 10:45 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 17 Jun 2010 21:25
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 |