如何使用C#显示机器的IP地址?
使用IPHostEntry.AddressList属性获取IP地址-
IPHostEntry myIP = Dns.GetHostEntry(hostName); IPAddress[] address = myIP.AddressList;
尝试以下代码以显示IP地址-
示例
using System;
using System.Net;
class Program {
static void Main() {
String hostName = string.Empty;
hostName = Dns.GetHostName();
Console.WriteLine("Hostname: "+hostName);
IPHostEntry myIP = Dns.GetHostEntry(hostName);
IPAddress[] address = myIP.AddressList;
for (int i = 0; i < address.Length; i++) {
Console.WriteLine("IP Address {1} : ",address[i].ToString());
}
Console.ReadLine();
}
}热门推荐
10 同事换单位简短祝福语
11 谢谢朋友的祝福语简短
12 立秋节气简短祝福语
13 新房祝福语简短10字
14 长辈新年祝福语大全简短
15 新年给大家简短祝福语
16 生日祝福语简短独特姑姑
17 芭比的婚礼祝福语简短
18 邀请新人祝福语简短英文