HostName, IP, and MAC Address






3.60/5 (32 votes)
Jan 24, 2005

351827

21042
This will guide you to understand and trace network host information, IP, and MAC address information.
Introduction
This article is used to get the intranet information in a network. It shows information like the host name, corresponding IP address and also physical address.
Using the code
The code retrieves all the System names using the Directory entries information.
// // Use Your work Group WinNT://Baba(Work Group Name)
// DirectoryEntry DomainEntry =
// new DirectoryEntry("WinNT://" + this.TxtWorkGroup.Text.Trim());
// DomainEntry.Children.SchemaFilter.Add("computer");
Then we collect the IP address using the DNS.
// System.Net.IPHostEntry Tempaddr =
// (System.Net.IPHostEntry)Dns.GetHostByName(machine.Name);
// System.Net.IPAddress[] TempAd = Tempaddr.AddressList;
The physical MAC address is collected using the DLL "iphlpapi.dll" with the API SendARP()
.
For each System, we use the Hostname to retrieve the MAC address.
// [DllImport("iphlpapi.dll", ExactSpelling=true)]
// public static extern int SendARP( int DestIP, int SrcIP,
// [Out] byte[] pMacAddr, ref int PhyAddrLen );
Points of Interest
This is my first article in CodeProject.
History
- 01/24/2005
Article released.