using System.Net;
for people working in .net 1.1
// To Get the hostname
string getHost = System.Net.Dns.GetHostName();
// Display the hostname
MessageBox.Show(getHost);
// To Get the IP from the host name
string getIP = System.Net.Dns.GetHostByName(getHost).AddressList[0].ToString();
// Display the IP
MessageBox.Show(getIP);
For .net 2.0
repalce GetHostByName by GetHostEntry: