public AdaptersInfo() { _adapterList = new List<IP_ADAPTER_INFO>(); int cb = 0; int ret = GetAdaptersInfo(IntPtr.Zero, ref cb); IntPtr pInfo = LocalAlloc(0x40, cb); //LPTR ret = GetAdaptersInfo(pInfo, ref cb); if (ret == 0) { IP_ADAPTER_INFO info = new IP_ADAPTER_INFO(pInfo, 0); while (info != null) { IP_ADDR_STRING st = info.IpAddressList; _adapterList.Add(info); //listView1.Items.Add(new ListViewItem(new string[] { info.AdapterName, info.CurrentIpAddress.IpAddress.String, info.CurrentIpAddress.IpMask.String, info.GatewayList.IpAddress.String })); info = info.Next; } } LocalFree(pInfo); }
public AdaptersInfo() { _adapterList = new List <IP_ADAPTER_INFO>(); int cb = 0; int ret = GetAdaptersInfo(IntPtr.Zero, ref cb); IntPtr pInfo = LocalAlloc(0x40, cb); //LPTR ret = GetAdaptersInfo(pInfo, ref cb); if (ret == 0) { IP_ADAPTER_INFO info = new IP_ADAPTER_INFO(pInfo, 0); while (info != null) { IP_ADDR_STRING st = info.IpAddressList; _adapterList.Add(info); //listView1.Items.Add(new ListViewItem(new string[] { info.AdapterName, info.CurrentIpAddress.IpAddress.String, info.CurrentIpAddress.IpMask.String, info.GatewayList.IpAddress.String })); info = info.Next; } } LocalFree(pInfo); }