private void button1_Click(object sender, EventArgs e) {
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine("MAC Address: " + getMacAddress());
sb.AppendLine("Local IP Address: " + getLocalIPAddress());
sb.AppendLine("Public IP Address: " + getPublicIPAddress());
MessageBox.Show(sb.ToString());
}
public object getMacAddress() {
string result = "";
try {
System.Net.NetworkInformation.NetworkInterface[] nics =
System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
result = System.Text.RegularExpressions.
Regex.Replace(nics[0].GetPhysicalAddress().ToString(), "..(?=.)", "$&:");
} catch { }
return result;
}
public object getPublicIPAddress() {
string result = "";
try {
result = new System.Net.WebClient().DownloadString("http://icanhazip.com/").Trim();
} catch { }
return result;
}
public string getLocalIPAddress() {
string result = "";
try {
result = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList[0].ToString();
} catch { }
return result;
}