Click here to Skip to main content
Click here to Skip to main content

HostName, IP, and MAC Address

, 23 Jan 2005
Rate this:
Please Sign up or sign in to vote.
This will guide you to understand and trace network host information, IP, and MAC address information.

Sample Image - Host_Info_within_Network.jpg


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.


  • 01/24/2005

    Article released.


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


About the Author

Technical Lead
India India
I loves computers. I am interested in programming such like Networking using Sockets, Imaging, Telecom and robotics.
I am very much interested in programming in windows and Linux.
I am working with Verizon Data Services India Ltd.,

Comments and Discussions

GeneralHostname from IP Address PinmemberDaLucifer30-Jun-06 23:03 
GeneralRe: Hostname from IP Address PinmemberMahendranG25-Jul-06 17:57 
GeneralRe: Hostname from IP Address PinmemberDaLucifer26-Jul-06 5:07 
QuestionHow to Get MAC Address from an IP Address in Internet Pinmemberdathq22-May-06 7:02 
I have tried you code and it really good in a LAN. But when I use SendARP to recieve MAC address of an IP from internet, it doesn't work.
The returing MAC Address always be 00-00-00-00-00-00
I wonder that, does SendARP work only in a local netowrk? In this case, do you know any solution for my problem?
Thanks for your help!
AnswerRe: How to Get MAC Address from an IP Address in Internet Pinmemberdarkhuntercode28-Jan-11 9:25 
GeneralMAC Address of PC;s turned off... PinmemberKevinReece19-Apr-06 4:34 
GeneralRe: MAC Address of PC;s turned off... PinmemberMahendranG19-Apr-06 18:48 
GeneralVB.NET 2005 Example PinmemberFloatingPointCode6-Apr-06 4:43 
GeneralRe: VB.NET 2005 Example PinmemberMahendranG10-Apr-06 17:14 
GeneralRe: VB.NET 2005 Example PinmemberFloatingPointCode11-Apr-06 5:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 24 Jan 2005
Article Copyright 2005 by MahendranG
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid