C# Code to Help Identify a Computer
A few weeks ago, I was looking over the shoulder of one of security analysts at work getting the low down on some of the stuff he does to help protect the PC’s on our network when he mentioned it would be nice to have an app that would identify a computer and their IP address for the helpdesk and the network. Immediately I thought, “give me a break. We don’t already have access to something like that?” He went on to explain that a previous employee said something like that couldn’t be created. So, I accepted the challenge and discovered that it wasn’t much of a challenge at all.
First, lets look at what we needed to accomplish. Presently, our helpdesk has to talk many users through the whole right-click on My Computer select properties, etc. thing. Having worked helpdesk before, I know that repeating that 5 - 10 times a day gets old. Secondly, we had no good way of getting a PC’s IP address quickly.
The solution–A small windows application that simply lists that information.
The Code:
For this demonstration, you’ll need to include the following:
using System.Security.Principal; using System.Net;
To reveal a computer’s name, the following code is all you need.
string host = Dns.GetHostName();
To grab the IP address of the computer we build off of the host name by doing the following:
IPHostEntry ipHost = Dns.GetHostEntry(host); IPAddress[] addy = ipHost.AddressList; string ip = addy[0].ToString()
And there you have it. I took these four lines of code and made a quick little windows forms app so that all a user has to do is double click an icon on their PC and read the info to the helpdesk tech.
One thing to note… Windows Vista will return the IPv6 IP using the method demonstrated above.
No comments in this entry
Jump to comment form | comments rss | trackback url