zoukankan      html  css  js  c++  java
  • 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;
    }
    }
  • 相关阅读:
    bzoj 1061 单纯形法,或转化网络流(待补)
    bzoj 1007 计算几何,单调栈
    bzoj 1015 并查集,离线
    bzoj 1013 高斯消元
    java类继承HttpServlet类实现Servlet程序出现405错误:HTTP method POST is not supported by this URL
    算法的特性和算法设计的要求
    Java实现自定义异常类
    怎么查看 MySQL 数据文件在当前电脑的存储位置
    数据结构的分类
    JS实现“全选”和"全不选"功能
  • 原文地址:https://www.cnblogs.com/jinyu20180311/p/10312397.html
Copyright © 2011-2022 走看看