linux 混杂模式 收包,Linux下使用混杂模式抓包(2)
有时候不光要抓自己的包,还要抓目的地址不是本机地址的包,既是过路包,这时候就要将监听网卡设为混在模式
这里新添了头文件:
net/if.h 定义了ifreq的结构体,既是接口(interface)的信息头文件。
#include
#include
#include
#include
#include
#include
#include
#include
/**
* Set misc mode for interface
* \param if_name interface name we will set
* \param sockfd the socket id we will set
* */
int set_promisc (char *if_name, int sockfd)
{
struct ifreq ifr;
strcpy (ifr.ifr_name, if_name);
if (0 != ioctl (sockfd, SIOCGIFFLAGS, &ifr))
{
printf ("Get interface flag failed\n");
return -1;
}
/* add the misc mode */
ifr.ifr_flags |= IFF_PROMISC;
if (0 != ioctl (sockfd, SIOCSIFFLAGS, &ifr))
{
printf ("Set interface flag failed\n");
return -1;
}
}
int main (int argc, char *argv[])
{
int sockfd;
int ret = 0;
char buffer[1518] = {0};
char *eth_head = NULL;
if ((sockfd = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL))) < 0)
{
printf ("create socket failed\n");
return -1;
}
if (0 != set_promisc ("eth0", sockfd))
{
printf ("Failed to set interface promisc mode\n");
}
while (1)
{
memset (buffer, 0x0, sizeof (buffer));
ret = recvfrom (sockfd, buffer, sizeof (buffer), 0, NULL, NULL);
printf ("recview package length : %d\n", ret);
eth_head = buffer;
printf ("PACKAGE START\n");
/* get source and dectination mac address */
printf ("dectination mac:%02x-%02x-%02x-%02x-%02x-%02x,"
"source mac:%02x-%02x-%02x-%02x-%02x-%02x;\n", eth_head[0],
eth_head[1], eth_head[2], eth_head[3], eth_head[4],
eth_head[5], eth_head[6], eth_head[7], eth_head[8],
eth_head[9], eth_head[10], eth_head[11]);
printf ("eth_type:%02x%02x\n", eth_head[12], eth_head[13]);
/* ARP protocol flag */
if (0x08 == eth_head[12] && 0x06 == eth_head[13])
{
printf ("ARP source ip:%d.%d.%d.%d,destination ip:%d.%d.%d.%d;\n",
eth_head[28], eth_head[29], eth_head[30], eth_head[31],
eth_head[38], eth_head[39], eth_head[40], eth_head[41]);
}
/* IPv4 protocol flag */
else if (0x08 == eth_head[12] && 0x00 == eth_head[13])
{
if (0x45 == eth_head[14])
{
printf ("IPv4 source ip:%d.%d.%d.%d,destination ip:%d.%d.%d."
"%d;\n", eth_head[26], eth_head[27], eth_head[28],
eth_head[29], eth_head[30], eth_head[31],
eth_head[32], eth_head[33]);
}
else
{
printf ("p_head:%02x\n", eth_head[14]);
}
}
printf ("PACKAGE END\n");
}
return 0;
}
运行之后就会发现发往其它mac的包了。
linux 混杂模式 收包,Linux下使用混杂模式抓包(2)相关推荐
- linux怎么抓sip包,Ubuntu下使用Wireshark进行抓包分析(含SIP和RTP包)
遇到需要在Linux下抓包分析的问题,便用到了wireshark,非常强大的抓包分析软件,直接在系统里面安装,然后使用明亮抓包即可! 我这里用的是Ubuntuserver版,执行安装: 1.apt-g ...
- java socket 抓包_linux下用socket的抓包程序
void die(char *why, int n) { perror(why); exit(n); } int do_promisc(char *nif, int sock ) { struct i ...
- linux下wireshark使用笔记本网卡抓包配置
linux下wireshark使用笔记本网卡抓包命令: 可以先用ifconfig查看本地无线网卡,这里为wlp0s20f3 sudo killall -9 wpa_supplicant sudo if ...
- 安卓抓包工具 linux,Android 下使用tcpdump网络抓包方法
Android 下使用tcpdump网络抓包方法 抓包需要tcpdump以及Root权限,tcpdump在本文后有下载. 首先把tcpdump传进手机,用adb命令(放SD卡有时会有问题,我一次可以用 ...
- kali Linux宿主代理、v2ray代理、proxychain4代理和抓包环境Charles、burp的安装配置
目录 1.v2rayN内网配置 2.宿主代理配置 2.1配置proxychains4代理 2.2配置火狐浏览器代理 3.v2ray安装配置和使用 3.1 修改国内源 3.2 v2ray安装配置 3.3 ...
- 硬干货!一张图弄清楚在ESXi下如何进行网络抓包
对于网络问题,抓包一直是一个比较简单方便的"大招".由于在esxi环境下可以在不同的层面下抓包,因此在什么地方抓包,怎么抓包一直让我觉得很复杂,于是每次操作之前我都要再检查一次手册 ...
- iOS 10.3下解决Fiddler代理抓包ssl证书信任问题
iOS 10.3下解决Fiddler代理抓包ssl证书信任问题 参考文章: (1)iOS 10.3下解决Fiddler代理抓包ssl证书信任问题 (2)https://www.cnblogs.com/ ...
- esxi vsphere的端口_硬干货!一张图弄清楚在ESXi下如何进行网络抓包
对于网络问题,抓包一直是一个比较简单方便的"大招".由于在esxi环境下可以在不同的层面下抓包,因此在什么地方抓包,怎么抓包一直让我觉得很复杂,于是每次操作之前我都要再检查一次手册 ...
- mac下HTTP与HTTPS抓包
mac下HTTP与HTTPS抓包 HTTP抓包流程 1. 在mac 电脑 上下载代理软件,charlse或者fiddler均可以: 下载方法:http://www.charlesproxy.com/可 ...
- 安利一个Mac下好用的抓包工具-Charles
Charles:让天底下没有难抓的包. 前言 今天给大家推荐一个我所使用过的抓包工具中最好用的抓包工具-Charles(音译:查尔斯),它可以抓各端发起的网络请求,我主要用来抓移动设备上的请求,上次小 ...
最新文章
- ML之SVM:调用(sklearn的lfw_people函数在线下载55个外国人图片文件夹数据集)来精确实现人脸识别并提取人脸特征向量
- [PowerShell]人人都值得学一点PowerShell实现自动化(2)有哪些可用的场景及方式?
- akshare写etf动量滚动策略
- url中隐藏php后缀,url中如何隐藏.php
- a4988 脉宽要求_A4982/A4984/A4985和A4988设备主要针对办公室自动化市场
- 【C语言笔记结构体】
- Singularity将本地SIF文件,转成sandbox
- PE+windows系统+苹果网站整理
- 进阿里一年中最好的机会
- OpenGL三维图形编程技术(转)
- JVAV中常见的十大异常
- 4K秒开,稀缺宝藏影视APP!
- 几款H桥电机驱动芯片直流有刷电机驱动芯片性能分析
- 一个蚂蚁程序员,曾经的辛酸面试历程
- bzoj1455罗马游戏*
- Java 提供的默认排序算法
- 网游限时器 v2.0 官方
- thymeleaf 数字格式化
- 手动管理采购订单周期的挑战以及如何应对
- c语言数据结构校园导游系统,校园导游系统课程设计报告
热门文章
- jeesite如何配置swagger_Spring Boot 2.x基础教程:Swagger接口分类与各元素排序问题详解...
- Autograd看这一篇就够了!
- socket.io简介
- [转]HTML DIV+CSS 命名规范大全
- [转]史上最全最强SpringMVC详细示例实战教程
- leetcode949. Largest Time for Given Digits
- 【WCF】无法加载协定为“ServiceReference1.xxxxxx”的终结点配置部分,因为找到了该协定的多个终结点配置。请按名称指示首选的终结点配置部分.
- 理解Java多线程高并发Executor框架的使用
- Flex(try-catch-finally)机制
- 【100题】第三十六 比赛淘汰问题(谷歌笔试)