pcap_set_rfmon不工作? [英] pcap_set_rfmon does not work?

查看:534
本文介绍了pcap_set_rfmon不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将我的设备设置为监视模式,我知道它能够在监视器模式下执行iwconfig wlan0模式监视器工作,我运行我的代码,我可以捕获数据包。

问题是,在libpcap它无法将我的设备设置为监视模式(没有进入上述命令行)。我无法捕获任何数据包,直到我手动连接到访问点。

  pcap_t * handler = pcap_create(wlan0,errbuff) 
if(pcap_set_rfmon(handler,1)== 0)
{
std :: cout< 监视模式有效<< std :: endl;
}
handler = pcap_open_live(wlan0,2048,0,512,errbuff);
int status = pcap_activate(handler); //这里返回0。

这是一个代码问题,还是pcap库问题?任何人都成功设置他们的设备到监视模式

解决方案

你不应该使用,而是使用一个Realtek2500 btw。 pcap_open_live pcap_create / pcap_activate 尝试执行

  pcap_t * handler = pcap_create(wlan0,errbuff); 
if(handler == NULL)
{
std :: cerr<< pcap_create failed:< errbuf< std :: endl;
return; //或退出或返回错误代码或某事
}
if(pcap_set_rfmon(handler,1)== 0)
{
std :: cout< 监视模式有效<< std :: endl;
}
pcap_set_snaplen(handler,2048); //将快照长度设置为2048
pcap_set_promisc(handler,0); //关闭混杂模式
pcap_set_timeout(handler,512); //将超时设置为512毫秒
int status = pcap_activate(handler);

,当然,检查 status


I am trying to set my device to monitor mode, and i know its capable of being in monitor mode doing a "iwconfig wlan0 mode monitor" works, i run my code and i can capture packets from anywhere.

The problem is that in libpcap it fails to set my device to monitor mode at all(without entering the above-mentioned command line).I can't capture any packets until i manually connect to a access point.

       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.

so is this a code problem, or the pcap library problem?Anybody successfully set their device to monitor mode without using command lines?I am using a Realtek2500 btw.

解决方案

You're not supposed to use pcap_open_live and pcap_create/pcap_activate in the same code. Try doing

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);

and, of course, check the value of status.

这篇关于pcap_set_rfmon不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆