KnowDotNet NetRefactor

Get an IP Name from its Numeric Address

by William Ryan
Print this Article Discuss in Forums

.NET has some really rich libraries for manipulating Sockets, TCP/IP and a whole lot of other things.  With merely Two lines of code and an IP Address, you can find out its nominal value:

For example:

IPHostEntry IP_Entry = Dns.GetHostByAddress("xxx.128.215.xxx");
string s =  IP_Entry.HostName.ToString();

Ok, now let's say that you want to find out the IP Hostname of the machine that the code is currently executing on.  Assuming you still have variable 's' in scope, this snippet will do it for you:

s = Dns.GetHostName();

These are very simple examples, but they can do quite a bit for you.  If you want to log who's using your app, perhaps as an audit trial, you can use this and the environment class Environ("username") and you can log not only the User that was logged onto a machine as well as the machine!

Writing Add-Ins for Visual Studio .NET
Writing Add-ins for Visual Studio .NET
by Les Smith
Apress Publishing