如何使用pcap_lookupdev查找无线设备
How to lookup wireless device with pcap_lookupdev?
这是目前为止我的代码。
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main(int & argc, char* argv[]){
char *net; /* dot notation of the network address */
char *mask;/* dot notation of the network mask */
int ret; /* return code */
char errbuf[PCAP_ERRBUF_SIZE];
bpf_u_int32 netp; /* ip */
bpf_u_int32 maskp;/* subnet mask */
struct in_addr addr;
char *dev; /* name of the device to use */
printf("Asking pcap to find a valid device for use to sniff on.n");
dev = pcap_lookupdev(errbuf);
if(dev == NULL) {
printf("pcap_lookupdev ERROR: %sn",errbuf);
exit(1);
}
printf("Printing out device name.n");
printf("DEV: %sn",dev);
printf("Asking pcap for the network address and mask of the device.n");
ret = pcap_lookupnet(dev,&netp,&maskp,errbuf);
if(ret == -1) {
printf("Unable to retrieve the network address and mask of the device. Error Description: %sn",errbuf);
exit(1);
}
printf("Get the network address in a human readable form,n");
addr.s_addr = netp;
net = inet_ntoa(addr);
if(net == NULL) {
printf("Unable to retrieve network address in human readable form.n");
perror("inet_ntoa");
exit(1);
}
printf("NET: %sn",net);
/* do the same as above for the device's mask */
addr.s_addr = maskp;
mask = inet_ntoa(addr);
if(mask == NULL) {
printf("Unable to retrieve device mask in human readable form. ");
perror("inet_ntoa");
exit(1);
}
printf("MASK: %sn",mask);
return 0;
}
/*
Output:
Asking pcap to find a valid device for use to sniff on.
Printing out device name.
DEV: eth0
Asking pcap for the network address and mask of the device.
Unable to retrieve the network address and mask of the device. Error Description: eth0: no IPv4 address assigned
*/
这是我的问题:我需要做什么才能让pcap_lookupdev查找无线设备(即wlan0)?
pcap_findalldevs的文档提示了pcap_lookupdev()没有找到任何合适的网络设备的原因:
请注意,可能存在无法打开的网络设备Pcap_open_live()被进程调用pcap_findalldevs(),因为,例如,该进程可能没有足够的权限打开它们用于捕获;如果是,这些设备将不会出现在列表
您可能没有必要的权限来捕获任何可用网络设备上的流量。尝试使用sudo运行程序,假设您在机器上具有管理员权限。
pcap_lookupdev()
将查找一个设备。这可能不是你想要的设备;如果你同时有有线和无线接口设备,它很可能会找到有线设备,这是而不是,因为它没有寻找无线设备,这是因为它碰巧是第一个找到的设备。
没有办法告诉它在无线设备上只看
获取libpcap可以处理的所有设备的列表,使用pcap_findalldevs()
。
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 在C++中查找文件
- 模板元程序查找相似的连续类型名称
- 在UNIX系统中使用DIR查找文件的字节大小
- 查找最接近的大于当前数字的数字的索引
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 查找后更改类变量
- 使用正则表达式regex_search在字符串中查找字符串
- 使用gcc从静态链接的文件中查找可选符号
- 在C++中查找范围的长度
- 算法问题:查找从堆栈中弹出的所有序列
- 在Windows中查找扬声器输出的当前音量级别
- 如何在C++中使用X509证书模在令牌中查找私钥
- 使用.find函数在c++中查找字符和另一个字符之间的大小
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 在 for 循环中查找问题时遇到困难
- 如何在文件中查找字节序列
- 试图创建一个多线程程序来查找0-100000000之间的总素数
- 使用堆查找第K个最大元素的时间复杂性
- 一个函数,用于查找字符串1包含字符串2 c++的次数