我试图将我的设备设置为监控模式,我知道它能够处于监控模式,执行"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.
Run Code Online (Sandbox Code Playgroud)
这是一个代码问题,还是pcap库的问题?有没有人成功将他们的设备设置为监控模式而不使用命令行?我正在使用Realtek2500 btw.
小智 11
你不应该使用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; // 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);
Run Code Online (Sandbox Code Playgroud)
当然,检查的价值status.
| 归档时间: |
|
| 查看次数: |
2501 次 |
| 最近记录: |