public static void Test() { IPSubnet ipRange = new IPSubnet("10.10.10.0", 24); Console.WriteLine(ipRange.NetworkAddress); Console.WriteLine(ipRange.BroadcastAddress); ipRange.setRandom(false); int count = (int)ipRange.size(); ArrayList list = new ArrayList(); foreach (String ip in ipRange) { //System.Console.Out.WriteLine(ip); list.Add(ip); if (--count == 0) { break; } } IPAddressList ipList = new IPAddressList(list); ipList.setRandom(false); count = (int)ipList.size(); foreach (String ip in ipList) { System.Console.Out.WriteLine(ip); if (--count == 0) { break; } } }
private void SetAfapterInfo(IPHelper.IP_ADAPTER_INFO adapterInfo) { m_adapterInfo=adapterInfo; m_ipAddressList = GetIpAddressList( adapterInfo.IpAddressList ); m_gatewaysList = GetIpGateways( adapterInfo.GatewayList ); }
private IPAddressList GetIpAddressList(IPHelper.IP_ADDR_STRING addr) { IPAddressList ipList = new IPAddressList(); ipList.Add( new IPAddress(addr.IpAddress.address,addr.IpMask.address) ); while(addr.Next != 0) { addr = (IPHelper.IP_ADDR_STRING)Marshal.PtrToStructure((IntPtr)addr.Next,typeof(IPHelper.IP_ADDR_STRING)); ipList.Add(new IPAddress(addr.IpAddress.address,addr.IpMask.address)); } return ipList; }