• c# 获取网络流量


    public class ip_helper
    {
    enum Constants {
    MAX_INTERFACE_NAME_LEN=256, MAXLEN_PHYSADDR=8,MAXLEN_IFDESCR=256
    }
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    public struct MIB_IFROW
    {
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst
    =(int)Constants.MAX_INTERFACE_NAME_LEN)]
    public string wszName;
    public uint dwIndex;
    public uint dwType;
    public uint dwMtu;
    public uint dwSpeed;
    public uint dwPhysAddrLen;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst
    =(int)Constants.MAXLEN_PHYSADDR)]
    public byte[] bPhysAddr;
    public uint dwAdminStatus;
    public uint dwOperStatus;
    public uint dwLastChange;
    public uint dwInOctets;
    public uint dwInUcastPkts;
    public uint dwInNUcastPkts;
    public uint dwInDiscards;
    public uint dwInErrors;
    public uint dwInUnknownProtos;
    public uint dwOutOctets;
    public uint dwOutUcastPkts;
    public uint dwOutNUcastPkts;
    public uint dwOutDiscards;
    public uint dwOutErrors;
    public uint dwOutQLen;
    public uint dwDescrLen;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst
    =(int)Constants.MAXLEN_IFDESCR)]
    public byte[] bDescr;
    }
    [StructLayout(LayoutKind.Sequential)]
    public struct MIB_IFTABLE
    {
    public uint dwNumEntries;
    public MIB_IFROW[] table;
    }
    [DllImport("IPHlpApi.dll")]
    public static extern uint GetIfTable(IntPtr pIfTable, ref uint pdwSize, bool
    bOrder);
    /// <summary>
    /// Description of MyClass.
    /// </summary>
    public ip_helper()
    {
    }
    public int InitGetIfTable()
    {
    uint size = 0;
    GetIfTable(IntPtr.Zero, ref size, false);
    IntPtr buf = Marshal.AllocHGlobal((int)size);
    GetIfTable(buf, ref size, false);
    int numEntries = Marshal.ReadInt32(buf);
    int pRows = 4 + (int)buf;
    MIB_IFROW[] rows = new MIB_IFROW[(int)numEntries];
    for ( int i = 0; i < numEntries; i++ )
    {
    rows[i] = Marshal.PtrToStructure((IntPtr)pRows, typeof(MIB_IFROW));
    pRows += Marshal.SizeOf(typeof(MIB_IFROW));
    }
    Marshal.FreeHGlobal(buf);
    return 1;
    }
    //
    private MIB_IFTABLE m_pfTable;
    private ulong m_dwAdapters;
    }
    }
  • 相关阅读:
    Entity Framework
    SQLiteHelp
    NLog日志记录
    C# 特性(Attribute)
    C# 正则表达式
    C#中显现串口通信SerialPort类
    C#.NET编码规范
    AspNetCore 限流中间件IpRateLimitMiddleware 介绍
    .Net Core中的Api版本控制
    C# Task的使用
  • 原文地址:https://www.cnblogs.com/jinyu20180311/p/10312397.html
Copyright © 2020-2023  润新知