1

デバイスをモニター モードに設定しようとしていますが、「iwconfig wlan0 モード モニター」を実行してモニター モードにできることはわかっています。コードを実行すると、どこからでもパケットをキャプチャできます。

問題は、libpcap で (上記のコマンド ラインを入力せずに) デバイスを監視モードに設定できないことです。手動でアクセス ポイントに接続するまで、パケットをキャプチャできません。

       pcap_t *handler = pcap_create("wlan0",errbuff);
       if(pcap_set_rfmon(handler,1)==0 )
       {
           std::cout << "monitor mode enabled" << std::endl;
       }
       handler=pcap_open_live ("wlan0", 2048,0,512,errbuff);
       int status = pcap_activate(handler); //it returns 0 here.

これはコードの問題ですか、それとも pcap ライブラリの問題ですか?コマンド ラインを使用せずにデバイスを監視モードに設定した人はいますか?私は Realtek2500 を使用しています。

4

3 に答える 3

11

pcap_open_live and pcap_create /pcap_activateを同じコードで使用することは想定されていません。やってみる

pcap_t *handler = pcap_create("wlan0",errbuff);
if (handler == NULL)
{
    std::cerr << "pcap_create failed: " << errbuf << std::endl;
    return; // or exit or return an error code or something
}
if(pcap_set_rfmon(handler,1)==0 )
{
    std::cout << "monitor mode enabled" << std::endl;
}
pcap_set_snaplen(handler, 2048);  // Set the snapshot length to 2048
pcap_set_promisc(handler, 0); // Turn promiscuous mode off
pcap_set_timeout(handler, 512); // Set the timeout to 512 milliseconds
int status = pcap_activate(handler);

もちろん、 の値を確認しますstatus

于 2011-07-26T05:16:38.543 に答える