【问题标题】:Monitoring Application Network Traffic in Qt在 Qt 中监控应用程序网络流量
【发布时间】:2013-09-10 14:15:30
【问题描述】:

我已经搜索了一段时间,但是有没有办法使用 Qt 库中已经内置的设备来监控来自特定应用程序的网络流量?我找到了一些使用 WinPCap 和其他类似实用程序之类的解决方案,但我希望将其全部保存在 Qt(C++ 中),因为这是我最熟悉的。

谢谢!任何指针都非常感谢!

【问题讨论】:

  • 你的平台是什么?如果它在 Windows 上,那么 WinPCap 是唯一的方法。要嗅探网络数据包,您需要内核空间驱动程序或类似的东西。 Qt 没有这样的功能。
  • 假设您能够修改 Qt 应用程序,是否可以在 read() 和 write() 调用周围放置包装函数来跟踪发送/接收的字节数?

标签: c++ qt


【解决方案1】:

一些 c# 嗅探器套接字创建示例。

    mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw,
                           ProtocolType.IP);

    // Bind the socket to the selected IP address
    mainSocket.Bind(newIPEndPoint(IPAddress.Parse(cmbInterfaces.Text),0));

    // Set the socket options
    mainSocket.SetSocketOption(SocketOptionLevel.IP,  //Applies only to IP packets
                               SocketOptionName.HeaderIncluded, //Set the include header
                               true);                           //option to true

    byte[] byTrue = newbyte[4]{1, 0, 0, 0};
    byte[] byOut = newbyte[4];

    //Socket.IOControl is analogous to the WSAIoctl method of Winsock 2
    mainSocket.IOControl(IOControlCode.ReceiveAll,  //SIO_RCVALL of Winsock
                         byTrue, byOut);

    //Start receiving the packets asynchronously
    mainSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None,
                            newAsyncCallback(OnReceive), null);

可能是 qt 提供了一些用于创建此类套接字的 api。创建此类套接字后,您将在解析标头和其他信息时获得原始数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    • 1970-01-01
    • 2016-02-26
    相关资源
    最近更新 更多