[英]Obtain network traffic with C++
我正在嘗試監視每月的網絡使用情況。 因為默認的Windows 10數據使用頁面不起作用,所以我借此機會學習了C ++,因為我熟悉Python和PHP等語言。
經過數小時的Google搜索,我得出的結論是WinPcap是我應該使用的模塊。 我是從這里下載的: https : //www.winpcap.org/devel.htm
我將.zip解壓縮到C ++控制台應用程序文件夾中。 所以我的應用程序在C:\\Visual Studio\\ProjectName123\\
,然后將WpdPack/
提取到其中。
我正在嘗試使用他們的示例代碼:
#include "pch.h"
#include "WpdPack\Include\pcap\pcap.h"
main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
int i = 0;
char errbuf[PCAP_ERRBUF_SIZE];
/* Retrieve the device list from the local machine */
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
{
fprintf(stderr, "Error in pcap_findalldevs_ex: %s\n", errbuf);
exit(1);
}
/* Print the list */
for (d = alldevs; d != NULL; d = d->next)
{
printf("%d. %s", ++i, d->name);
if (d->description)
printf(" (%s)\n", d->description);
else
printf(" (No description available)\n");
}
if (i == 0)
{
printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
return;
}
/* We don't need any more the device list. Free it */
pcap_freealldevs(alldevs);
}
我從以下幾個錯誤開始: identifier "PCAP_SRC_IF_STRING" is undefined
以下是T的一個示例,非常令人沮喪,並且它無法正常運行。 對C ++極為沮喪。
我們將不勝感激,特別說明了為什么我的代碼無法完美運行,該代碼完全遵循此示例 。
該示例代碼具有誤導性; 他們打算將PCAP_SRC_IF_STRING
替換為字符串值,而不是PCAP_SRC_IF_STRING
使用它。 要使用pcap_findalldevs_ex()
,需要將第一個參數作為字符串傳遞,以指定在哪里尋找適配器。 您應該發現以下方法效果更好:
pcap_findalldevs_ex("rpcap://",...
我建議您使用它作為參考: WinPCAP導出的函數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.