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

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

Share

About the Author

MahendranG
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

 
Questioncompatibility issue PinmemberMember 1108914315-Dec-14 23:47 
QuestionGet IP Address from HostName Pinmemberjohneloka20-Mar-14 0:20 
AnswerRe: Get IP Address from HostName PinmemberMahendranG12-Dec-14 14:37 
QuestionWorks only when connected to network using WIFI but doesn't work when connected via wires PinmemberMember 1049386314-Mar-14 18:00 
AnswerRe: Works only when connected to network using WIFI but doesn't work when connected via wires PinmemberMahendranG12-Dec-14 14:39 
GeneralThis code does not work on Windows 7.Please help. Pinmemberrohini.vangury1-Nov-10 3:17 
GeneralTo get the User Name of the client accessing a website PinmemberMoiz Ahmed9-Jan-10 0:28 
GeneralGreat article PinmemberEaverae2-Oct-09 1:58 
GeneralError when running your util HostNIPAddr.exe Pinmembersmith6667-Oct-08 9:06 
QuestionHow to Get WorkGroupNames in LAN PinmemberGowri12345613-Jun-08 2:25 
Generalworkgroup n ames in lan Pinmemberthiruvadi_anand31-Mar-08 2:58 
Questionno working in other range IP Pinmemberpablohack5-Sep-07 0:23 
GeneralUsage of variable names. PinmemberDesotron17-May-07 7:34 
GeneralHelp me! Pinmembernguyenquanglamcnttk278-May-07 0:57 
QuestionIs there a way to detect Network Printers' IP addresses? PinmemberJan Palmer26-Dec-06 0:55 
QuestionMAC address of Linux, Solaris... machine? Pinmemberhnim20-Dec-06 21:46 
AnswerRe: MAC address of Linux, Solaris... machine? PinmemberMahendranG21-Dec-06 7:54 
GeneralRe: MAC address of Linux, Solaris... machine? Pinmemberhnim25-Dec-06 21:35 
GeneralRe: MAC address of Linux, Solaris... machine? PinmemberMahendranG26-Dec-06 7:53 
QuestionHow to get the MAC from NIC Hardware PinmemberReader Man San31-Oct-06 21:51 
GeneralHostname from IP Address PinmemberDaLucifer1-Jul-06 0:03 
GeneralRe: Hostname from IP Address PinmemberMahendranG25-Jul-06 18:57 
GeneralRe: Hostname from IP Address PinmemberDaLucifer26-Jul-06 6:07 
thanx 4 the reply...
 
anyways... the above problem turns out to be a microsoft bug in the windows Xp, which they will fix in windows vista... found that after racking my brains for a long time on this!!
 

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=97815

QuestionHow to Get MAC Address from an IP Address in Internet Pinmemberdathq22-May-06 8:02 
AnswerRe: How to Get MAC Address from an IP Address in Internet Pinmemberdarkhuntercode28-Jan-11 10:25 
GeneralMAC Address of PC;s turned off... PinmemberKevinReece19-Apr-06 5:34 
GeneralRe: MAC Address of PC;s turned off... PinmemberMahendranG19-Apr-06 19:48 
GeneralVB.NET 2005 Example PinmemberFloatingPointCode6-Apr-06 5:43 
GeneralRe: VB.NET 2005 Example PinmemberMahendranG10-Apr-06 18:14 
GeneralRe: VB.NET 2005 Example PinmemberFloatingPointCode11-Apr-06 6:04 
GeneralRe: VB.NET 2005 Example Pinmemberjuacar0129-Jul-06 10:20 
GeneralsendARP PinmemberESTANNY27-Jan-06 5:50 
Generalworkgroup name Pinmember101624-Jan-06 4:33 
GeneralRe: workgroup name PinmemberESTANNY27-Jan-06 5:54 
GeneralRe: workgroup name [modified] Pinmemberrchi83-Sep-07 22:04 
GeneralRe: workgroup name PinmemberFloatingPointCode6-Apr-06 5:39 
Generalwirless Pinmemberaglt11-Sep-05 3:24 
GeneralRe: wirless PinsussAnonymous16-Sep-05 4:37 
Generaldetermining type of connection Pinmembershihab1234567824-Jul-05 7:35 
GeneralRe: determining type of connection PinsussAnonymous27-Jul-05 8:19 
Generaldetect multiple lan cards PinmemberAdnan Siddiqi17-Apr-05 21:48 
GeneralRe: detect multiple lan cards PinmemberMahendranG17-Apr-05 23:49 
GeneralRe: detect multiple lan cards PinmemberAdnan Siddiqi18-Apr-05 0:47 

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 | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 24 Jan 2005
Article Copyright 2005 by MahendranG
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid