public void GetIfEntry2Test() { var row = new MIB_IF_ROW2(primaryAdapter.IfIndex); Assert.That(GetIfEntry2(ref row), Is.Zero); Assert.That(row.InterfaceLuid, Is.EqualTo(primaryAdapter.Luid)); }
public void GetIfEntry2ExTest() { var row = new MIB_IF_ROW2(primaryAdapter.IfIndex); Assert.That(GetIfEntry2Ex(MIB_IF_ENTRY_LEVEL.MibIfEntryNormalWithoutStatistics, ref row), Is.Zero); Assert.That(row.InterfaceLuid, Is.EqualTo(primaryAdapter.Luid)); }
public void ReckonSpeed() { var iftable1 = GetIfTable(); long inSpeed1 = iftable1.Sum(m => m.dwInOctets); long outSpeed1 = iftable1.Sum(m => m.dwOutOctets); Thread.Sleep(1000); var iftable2 = GetIfTable(); var inSpeed2 = iftable2.Sum(m => m.dwInOctets); var outSpeed2 = iftable2.Sum(m => m.dwOutOctets); m_InSpeed = inSpeed2 - inSpeed1; m_OutSpeed = outSpeed2 - outSpeed1; var ada = GetInterfaceInfo(); ulong total = 0; foreach (var a in ada.Adapter) { MIB_IF_ROW2 row = new MIB_IF_ROW2(a.Index); GetIfEntry2(ref row); if (row.InOctets > 0) { total += row.ReceiveLinkSpeed; } } m_SpeedTotal = total / 8; }
private static MIB_IF_ROW2 GetIfEntry(int index) { if (adapters.TryGetValue(index, out var row)) { return(row); } row = new MIB_IF_ROW2((uint)index); GetIfEntry2(ref row).ThrowIfFailed(); adapters.Add(index, row); return(row); }
public object System() { SystemInfo sys = new SystemInfo(); var memoryLoad = 100 - ((double)sys.MemoryAvailable / (double)sys.PhysicalMemory) * 100; var cpuLoad = sys.CpuLoad; var iftable1 = IpHlpApi.GetIfTable(); long inSpeed1 = iftable1.Sum(m => m.dwInOctets); long outSpeed1 = iftable1.Sum(m => m.dwOutOctets); Thread.Sleep(1000); var iftable2 = IpHlpApi.GetIfTable(); var inSpeed2 = iftable2.Sum(m => m.dwInOctets); var outSpeed2 = iftable2.Sum(m => m.dwOutOctets); var inSpeed = inSpeed2 - inSpeed1; var outSpeed = outSpeed2 - outSpeed1; var ada = IpHlpApi.GetInterfaceInfo(); ulong total = 0; foreach (var a in ada.Adapter) { MIB_IF_ROW2 row = new MIB_IF_ROW2(a.Index); IpHlpApi.GetIfEntry2(ref row); if (row.InOctets > 0) { total += row.ReceiveLinkSpeed; } } total = total / 8; return(new { memoryLoad = memoryLoad, cpuLoad = cpuLoad, inSpeed = (double)inSpeed * 100 / Convert.ToDouble(total), outSpeed = (double)outSpeed * 100 / Convert.ToDouble(total) }); }