对几个IP地址集合的定义:
privateList_localAddressFamily = new List();//本机IP地址集合
privateList_subNetAddressFamily = new List();//子网掩码集合
privateList_defaultIPGateway = new List();// 默认网关集合
privateList _broadcastFamily= new List();//广播地址
比较简单的方式是借助C#已封装好的类来进行操作:
this._hostName = Dns.GetHostName();
IPHostEntry ipHostEntry=Dns.GetHostByName(this._hostName);
this._localAddressFamily.AddRange(ipHostEntry.AddressList);
// 至此 ipHostEntry.AddressList就是IP地址的集合
NetworkInterface[] adapters=NetworkInterface.GetAllNetworkInterfaces();
// 至此 adapters保存了本机所有的网卡适配器信息
NetworkInterface属性如下:
foreach (NetworkInterface ni in adapters) {
IPInterfaceProperties ipProperties =ni.GetIPProperties();
UnicastIPAddressInformation curIP =ipProperties.Uni