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

HostName, IP, and MAC Address

By , 23 Jan 2005
 

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

About the Author

MahendranG
Technical Lead
India India
Member
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.,

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralThis code does not work on Windows 7.Please help.memberrohini.vangury1 Nov '10 - 2:17 
GeneralTo get the User Name of the client accessing a websitememberMoiz Ahmed8 Jan '10 - 23:28 
GeneralGreat articlememberEaverae2 Oct '09 - 0:58 
GeneralError when running your util HostNIPAddr.exemembersmith6667 Oct '08 - 8:06 
QuestionHow to Get WorkGroupNames in LANmemberGowri12345613 Jun '08 - 1:25 
Generalworkgroup n ames in lanmemberthiruvadi_anand31 Mar '08 - 1:58 
Questionno working in other range IPmemberpablohack4 Sep '07 - 23:23 
GeneralUsage of variable names.memberDesotron17 May '07 - 6:34 
GeneralHelp me!membernguyenquanglamcnttk277 May '07 - 23:57 
QuestionIs there a way to detect Network Printers' IP addresses?memberJan Palmer25 Dec '06 - 23:55 
QuestionMAC address of Linux, Solaris... machine?memberhnim20 Dec '06 - 20:46 
AnswerRe: MAC address of Linux, Solaris... machine?memberMahendranG21 Dec '06 - 6:54 
GeneralRe: MAC address of Linux, Solaris... machine?memberhnim25 Dec '06 - 20:35 
Hi Mahendran,
I intend to develop a web-based application for using in our local network.
The website will get MAC address of client machine whenever there is a request in order to do some checking. The client machines can be any kind of Windows, Solaris, Linux OSs; the server is Windows server 2003.
To obtain MAC address of client machine, I intend to use the function SendARP. I tried in machines with Windows OS and it ran well.
But how about with others non-Windows OS? Do you think that the website can also take MAC address of client who uses these OSs to access?
Where will this function be invokedConfused | :confused: ? In server or in client? If it runs on server (Windows 2003) I think it canRoll eyes | :rolleyes:
 
Minh

GeneralRe: MAC address of Linux, Solaris... machine?memberMahendranG26 Dec '06 - 6:53 
QuestionHow to get the MAC from NIC HardwarememberReader Man San31 Oct '06 - 20:51 
GeneralHostname from IP AddressmemberDaLucifer30 Jun '06 - 23:03 
GeneralRe: Hostname from IP AddressmemberMahendranG25 Jul '06 - 17:57 
GeneralRe: Hostname from IP AddressmemberDaLucifer26 Jul '06 - 5:07 
QuestionHow to Get MAC Address from an IP Address in Internetmemberdathq22 May '06 - 7:02 
AnswerRe: How to Get MAC Address from an IP Address in Internetmemberdarkhuntercode28 Jan '11 - 9:25 
GeneralMAC Address of PC;s turned off...memberKevinReece19 Apr '06 - 4:34 
GeneralRe: MAC Address of PC;s turned off...memberMahendranG19 Apr '06 - 18:48 
GeneralVB.NET 2005 ExamplememberFloatingPointCode6 Apr '06 - 4:43 
GeneralRe: VB.NET 2005 ExamplememberMahendranG10 Apr '06 - 17:14 
GeneralRe: VB.NET 2005 ExamplememberFloatingPointCode11 Apr '06 - 5:04 
GeneralRe: VB.NET 2005 Examplememberjuacar0129 Jul '06 - 9:20 
GeneralsendARPmemberESTANNY27 Jan '06 - 4:50 
Generalworkgroup namemember101624 Jan '06 - 3:33 
GeneralRe: workgroup namememberESTANNY27 Jan '06 - 4:54 
GeneralRe: workgroup name [modified]memberrchi83 Sep '07 - 21:04 
GeneralRe: workgroup namememberFloatingPointCode6 Apr '06 - 4:39 
Generalwirlessmemberaglt11 Sep '05 - 2:24 
GeneralRe: wirlesssussAnonymous16 Sep '05 - 3:37 
Generaldetermining type of connectionmembershihab1234567824 Jul '05 - 6:35 
GeneralRe: determining type of connectionsussAnonymous27 Jul '05 - 7:19 
Generaldetect multiple lan cardsmemberAdnan Siddiqi17 Apr '05 - 20:48 
GeneralRe: detect multiple lan cardsmemberMahendranG17 Apr '05 - 22:49 
GeneralRe: detect multiple lan cardsmemberAdnan Siddiqi17 Apr '05 - 23:47 

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 24 Jan 2005
Article Copyright 2005 by MahendranG
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid