今天有需求要用tcpdump,给一个我使用的例子:

sudo /usr/sbin/tcpdump  dst 10.20.137.24 and tcp port 8080 -A -s0  -w nouse

-A 表示只用ASCII码显示, 方便查看网页

-x 表示用16进制

-X 表示16进制和ASCII码同时显示

-s0 表示不限制包的大小

-w 表示写入文件

参考了下面的文章,不胜感激。

Let assume ,I wanna capture tcp packets that flow over eth1 port 6881. The dump file with be save as test.pcap.

tcpdump -w test.pcap -i eth1 tcp port 6881

Simple right? What if at the same time I am interested on getting packets on udp port 33210 and 33220?

tcpdump -w test.pcap -i eth1 tcp port 6881 or udp \( 33210 or 33220 \)

‘\’ is an escape symbol for ‘(’ and ‘)’. Logic OR implies PLUS (+). In plain text is I want to capture tcp packets flows over port 6881 plus udp ports 33210 and 33220.

Careful with ‘and’ in tcpdump filter expression, it means intersection. Thats why I put ‘or’ instead of and within udp port 33210 and 33220. The usage of ‘and’ in tcpdump will be illustrate later.

Ok, how about reading pcap that I saved previously?

tcpdump -nnr test.pcap

The -nn is to tell tcpdump not to resolve DNS on IP and Ports, where r is read.

Adding -tttt to makes the timestamp appears more readable format.

tcpdump -ttttnnr test.pcap

How about capture based on IP ?
You need to tell tcpdump which IP you are interested in? Destination IP? or Source IP ? Let say I wanna sniff on destination IP 10.168.28.22 tcp port 22, how should i write?

tcpdump -w test.pcap dst 10.168.28.22 and tcp port 22

So the ‘and’ makes the intersection of destination IP and port.

By default the sniff size of packets is 96 bytes, you somehow can overload that size by specified with -s.

tcpdump -w test.pcap -s 1550 dst 10.168.28.22 and tcp port 22

Some version of tcpdump allows you to define port range. You can as bellow for capturing packets based on a range of tcp port.

tcpdump tcp portrange 20-24

Bare in mind, the line above I didn’t specified -w which it won’t write to a file but i will just print the captured packets on the screen.

tcpdump示例的更多相关文章

  1. 抓包工具tcpdump用法说明

    tcpdump采用命令行方式对接口的数据包进行筛选抓取,其丰富特性表现在灵活的表达式上. 不带任何选项的tcpdump,默认会抓取第一个网络接口,且只有将tcpdump进程终止才会停止抓包. 例如: ...

  2. tcpdump抓包工具用法说明

    tcpdump采用命令行方式对接口的数据包进行筛选抓取,其丰富特性表现在灵活的表达式上. 不带任何选项的tcpdump,默认会抓取第一个网络接口,且只有将tcpdump进程终止才会停止抓包. 例如: ...

  3. 抓包工具 tcpdump 用法说明

    tcpdump采用命令行方式对接口的数据包进行筛选抓取,其丰富特性表现在灵活的表达式上. 不带任何选项的tcpdump,默认会抓取第一个网络接口,且只有将tcpdump进程终止才会停止抓包. 例如: ...

  4. [转帖]tcpdump详细教程

    tcpdump详细教程 https://www.jianshu.com/p/d9162722f189 tcpdump tcpdump - dump traffic on a network tcpdu ...

  5. 【转载】抓包工具tcpdump用法说明

    转载地址:http://www.cnblogs.com/f-ck-need-u/p/7064286.html tcpdump采用命令行方式对接口的数据包进行筛选抓取,其丰富特性表现在灵活的表达式上. ...

  6. 抓包工具tcpdump用法说明--1

    本文目录: 1.1 tcpdump选项 1.2 tcpdump表达式 1.3 tcpdump示例 tcpdump采用命令行方式对接口的数据包进行筛选抓取,其丰富特性表现在灵活的表达式上. 不带任何选项 ...

  7. tcpdump用法说明

    tcpdump采用命令行方式对接口的数据包进行筛选抓取,其丰富特性表现在灵活的表达式上. 不带任何选项的tcpdump,默认会抓取第一个网络接口,且只有将tcpdump进程终止才会停止抓包. 例如: ...

  8. 超详细的网络抓包神器 tcpdump 使用指南

    原文链接:Tcpdump 示例教程 本文主要内容翻译自<Tcpdump Examples>. tcpdump 是一款强大的网络抓包工具,它使用 libpcap 库来抓取网络数据包,这个库在 ...

  9. monitor a local unix domain socket like tcpdump

    Can I monitor a local unix domain socket like tcpdump? - Super User https://superuser.com/questions/ ...

随机推荐

  1. META-INF中的INF的意思

    1 META是元的意思,比如meta data,元数据. 2 什么是meta data 元数据就是描述其它数据的数据,比如web page中的meta data,包括关键字,对该网页的描述等等. 3 ...

  2. 存储过程 & 触发器

    触发器主要是通过事件进行触发而被执行的,而存储过程可以通过存储过程名字而被直接调用.当对某一表进行诸如UPDATE. INSERT. DELETE 这些操作时, 就会自动执行触发器所定义的SQL 语句 ...

  3. spring data jpa 利用@Query进行查询

    参照https://blog.csdn.net/yingxiake/article/details/51016234#reply https://blog.csdn.net/choushi300/ar ...

  4. xpath中如何使用变量

    xpath (python)xpath中如何使用变量描述: 在xpath中该如何使用变量,想选择id是某个值的元素,这个值是个变量. response.xpath('//div[@id=val]'). ...

  5. R语言图形base系统(一)

           一般R作图有三大绘图系统:base系统.ggplot2绘图系统.lattice绘图系统.        本篇主要介绍base系统绘图时的图形参数.一般用plot()函数来完成.在R中,若 ...

  6. R语言数据管理(三):数据读入

    R的数据读入非常灵活,即可以在R软件中直接输入,也可以读入外部数据. 一.直接输入数据 ①c()函数 ②scan()函数 其功能类似c()函数,scan()实际上是一种键盘输入数据函数.当输入scan ...

  7. GIT笔记:GITHUB教程【官方自译版】

    GIT笔记:将项目发布到GITHUB GITHUB是什么 GitHub是版本控制和协作的代码托管平台.它可以让你和其他人在任何地方一起工作. 1.创建一个新的仓库 存储库通常用于组织单个项目.存储库可 ...

  8. platform-tools

    platform-tools包含开发app的平台依赖的开发和调试工具,包括 adb.fastboot等 android sdk里的各目录作用 AVD Manager.exe:虚拟机管理工具,用于建立和 ...

  9. 简介windows的环境变量

    环境变量一般是指在操作系统中用来指定操作系统运行环境的一些参数,比如临时文件夹位置和系统文件夹位置等.这点有点类似于DOS时期的默认路径,当你运行某些程序时除了在当前文件夹中寻找外,还会到设置的默认路 ...

  10. Oracle数据库体系结构(1)整体概述

    oracle数据库的存储结构: 逻辑存储结构:oracle内部的组织和管理数据的方式 物理存储结构:oracle外部(操作系统)组织和管理数据的方式 oracle对逻辑存储结构和物理存储结构的管理是分 ...