I have to develop an desktop app which shall allow me file sharing on a local network.For this, I am able to get a listview
of devices hostname but when it comes to know their IP Addresses and MAC I went to see System.net
and several other MSDN forums (where the help was available for metro apps).
How can i get the IP addresses & MAC Address of all devices on my local network?
I am using DirectoryEntry
to get User Names and get displayed in listview
.
lstLocal.Items.Clear();
lstLocal.View = View.Details;
lstLocal.FullRowSelect = true;
DirectoryEntry root = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry computers in root.Children)
{
foreach (DirectoryEntry computer in computers.Children)
{
if (computer.Name != "Schema")
{
ListViewItem item = new ListViewItem(computer.Name);
// item.SubItems.Add(computer.Name);
//MessageBox.Show(computer.Name);
lstLocal.Items.Add(item);
}
}
}
UPDATE: I used
var hostname = Dns.GetHostName();
var ipadd = Dns.GetHostAddresses(hostname);
but the address is in IPV6 returned.I need it in IPV4.
There are inbuilt classes to find the IP/Mac addresses. Please check this link.
Snippet taken from above: