Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

HostName, IP, and MAC Address

0.00/5 (No votes)
23 Jan 2005 5  
This will guide you to understand and trace network host information, IP, and MAC address information.

Sample Image - Host_Info_within_Network.jpg

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here