对几个IP地址集合的定义:
privateList<IPAddress>_localAddressFamily = new List<IPAddress>();//本机IP地址集合
privateList<IPAddress>_subNetAddressFamily = new List<IPAddress>();//子网掩码集合
privateList<IPAddress>_defaultIPGateway = new List<IPAddress>();// 默认网关集合
privateList<IPAddress> _broadcastFamily= new List<IPAddress>();//广播地址
比较简单的方式是借助C#已封装好的类来进行操作:
this._hostName = Dns.GetHostName();
IPHostEntry ipHostEntry=Dns.GetHostByName(this._hostName);
this._localAddressFamily.AddRange(ipHostEntry.AddressList);
// 至此 ipHostEntry.AddressList就是IP地址的集合
NetworkInterface[] adapters=NetworkInterface.GetAllNetworkInterfaces();