Click here to Skip to main content
15,311,151 members
Articles / Programming Languages / C#
Posted 23 Jan 2005


104 bookmarked

HostName, IP, and MAC Address

Rate me:
Please Sign up or sign in to vote.
3.60/5 (32 votes)
23 Jan 2005
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

QuestionFor VB .Net Pin
Muhd Hamni Adam18-Jan-17 17:34
MemberMuhd Hamni Adam18-Jan-17 17:34 
QuestionGet LAN network Camera's IP address Pin
rselone27-May-16 17:07
Memberrselone27-May-16 17:07 
QuestionI can not download the code Pin
xu_xuthus2-Mar-16 15:35
Memberxu_xuthus2-Mar-16 15:35 
AnswerRe: I can not download the code Pin
Garth J Lancaster2-Mar-16 16:20
professionalGarth J Lancaster2-Mar-16 16:20 
GeneralRe: I can not download the code Pin
xu_xuthus3-Mar-16 20:34
Memberxu_xuthus3-Mar-16 20:34 
QuestionCan you please also add a Export to CSV or TXT button for the same Pin
babai9326-Jan-16 20:27
Memberbabai9326-Jan-16 20:27 
QuestionProgram in C or C++ to get @IP, @MAC, HOSTNAME of a computer (or any computer) in a local network Pin
faical malali24-Jul-15 9:03
Memberfaical malali24-Jul-15 9:03 
QuestionHostName, IP, and MAC Address Pin
Member 1115979626-Jan-15 20:02
MemberMember 1115979626-Jan-15 20:02 
Questioncompatibility issue Pin
Member 1108914315-Dec-14 22:47
MemberMember 1108914315-Dec-14 22:47 
QuestionGet IP Address from HostName Pin
johneloka19-Mar-14 23:20
Memberjohneloka19-Mar-14 23:20 
AnswerRe: Get IP Address from HostName Pin
MahendranG12-Dec-14 13:37
MemberMahendranG12-Dec-14 13:37 
QuestionWorks only when connected to network using WIFI but doesn't work when connected via wires Pin
Member 1049386314-Mar-14 17:00
MemberMember 1049386314-Mar-14 17:00 
AnswerRe: Works only when connected to network using WIFI but doesn't work when connected via wires Pin
MahendranG12-Dec-14 13:39
MemberMahendranG12-Dec-14 13:39 
GeneralThis code does not work on Windows 7.Please help. Pin
rohini.vangury1-Nov-10 2:17
Memberrohini.vangury1-Nov-10 2:17 
GeneralTo get the User Name of the client accessing a website Pin
Moiz Ahmed8-Jan-10 23:28
MemberMoiz Ahmed8-Jan-10 23:28 
GeneralGreat article Pin
Eaverae2-Oct-09 0:58
MemberEaverae2-Oct-09 0:58 
GeneralError when running your util HostNIPAddr.exe Pin
smith6667-Oct-08 8:06
Membersmith6667-Oct-08 8:06 
QuestionHow to Get WorkGroupNames in LAN Pin
Gowri12345613-Jun-08 1:25
MemberGowri12345613-Jun-08 1:25 
Generalworkgroup n ames in lan Pin
thiruvadi_anand31-Mar-08 1:58
Memberthiruvadi_anand31-Mar-08 1:58 
Questionno working in other range IP Pin
pablohack4-Sep-07 23:23
Memberpablohack4-Sep-07 23:23 
GeneralUsage of variable names. Pin
Desotron17-May-07 6:34
MemberDesotron17-May-07 6:34 
GeneralHelp me! Pin
nguyenquanglamcnttk277-May-07 23:57
Membernguyenquanglamcnttk277-May-07 23:57 
QuestionIs there a way to detect Network Printers' IP addresses? Pin
Jan Palmer25-Dec-06 23:55
MemberJan Palmer25-Dec-06 23:55 
QuestionMAC address of Linux, Solaris... machine? Pin
hnim20-Dec-06 20:46
Memberhnim20-Dec-06 20:46 
AnswerRe: MAC address of Linux, Solaris... machine? Pin
MahendranG21-Dec-06 6:54
MemberMahendranG21-Dec-06 6:54 

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

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