博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tcpdump基本用法
阅读量:2447 次
发布时间:2019-05-10

本文共 2921 字,大约阅读时间需要 9 分钟。

什么是tcpdump

Tcpdump  prints  out  the  headers of packets on a network interface that match the boolean expression.

 

常用选项

-w可以将结果写入文件,而-r可以从制定文件读取数据

-c 接收指定数量的包后自动退出

-i 监听的网卡

-n 禁止将IP解析为域名

 

监听类型

Host –默认/Net/ Port

 

监听传输方向

Src/Dst/Dst or src –默认/Dst and src

 

监听传输协议

Fddi/Ip/Arp/Rarp/Tcp/Udp

 

逻辑运算符

取非运算Not  !

与运算 and &&

或运算 or ||

 

具体语法

截获主机ABC的通信

Tcpdump host A and \(B or C\)

获取主机A除了和B之外所有的通信IP

Tcpdump ip host A and ! B

获取主机A接收的telnet

Tcpdump tcp port 23 dst host A

 

案例

1

通过shell自动捕获长时间运行的事务并用tcpdump跟踪

#!/bin/bash

# Begin by deleting things more than 7 days old

find /root/tcpdumps/ -type f -mtime +7 -exec rm -f '{}' \;

# Bail out if the disk is more than this %full.

PCT_THRESHOLD=95

# Bail out if the disk has less than this many MB free.

MB_THRESHOLD=100

# Make sure the disk isn't getting too full.

avail=$(df -m -P /root/tcpdumps/ | awk '/^\//{print $4}');

full=$(df -m -P /root/tcpdumps/ | awk '/^\//{print $5}' | sed -e 's/%//g');

if [ "${avail}" -le "${MB_THRESHOLD}" -o "${full}" -ge "${PCT_THRESHOLD}" ]; then

   echo "Exiting, not enough free space (${full}%, ${avail}MB free)">&2

   exit 1

fi

 

host=$(mysql -ss -e 'SELECT p.HOST FROM information_schema.innodb_lock_waits w INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id INNER JOIN information_schema.processlist p on b.trx_mysql_thread_id = p.ID LIMIT 1')

if [ "${host}" ]; then

   echo "Host ${host} is blocking"

   port=$(echo ${host} | cut -d: -f2)

   tcpdump -i eth0 -s 65535 -x -nn -q -tttt port 3306 and port ${port} > /root/tcpdumps/`date +%s`-tcpdump &

   mysql -e 'show innodb status\Gshow full processlist' > /root/tcpdumps/`date +%s`-innodbstatus

   pid=$!

   sleep 30

   kill ${pid}

fi

 

2

利用tcpdump捕获mysql运行的sql

#!/bin/bash
#this script. used montor mysql network traffic.echo sql
 

while(<>) { chomp; next if /^[^ ]+[ ]*$/;

  if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i) {

    if (defined $q) { print "$q\n"; }

    $q=$_;

  } else {

    $_ =~ s/^[ \t]+//; $q.=" $_";

  }

}'

下面是执行脚本的输出
SELECT b.id FROM module as a,rights as b where a.id=b.module_id and b.sid='179' and a.pname like 'vip/member_order_manage.php%'
SELECT count(id) as cc,sum(cash) as total from morder_stat_all  where (ymd BETWEEN '1312214400' and '1312336486') and depart_id=5 an
d order_class=2
select id,name from media where symd='0000-00-00'
select id,name from depart where s_flag=' '  and noff=1 order by sno
select id,name from plank where depart_id=5  and noff=1 order by no
select id,name from grp where plank_id=0  and noff=1 order by no
select id,CONCAT(pname,'-',name) as name from pvc order by pname
select id,CONCAT(no,'-',name) as name from local where pvc_id=0 order by no
select id,name from product_breed
select color_name from product_color where id=5
select id,name from product where id = '0'

 

 

 

可使用来wireshark图形化解析

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15480802/viewspace-757723/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15480802/viewspace-757723/

你可能感兴趣的文章
github请求超时_在GitHub中创建第一个请求请求
查看>>
构建自定义JavaScript Scrollspy导航
查看>>
laravel/dusk_Laravel Dusk简介
查看>>
slim3框架 教程_SLIM 3入门,PHP微框架
查看>>
谷歌中阻止冒泡在火狐中失效_如何在Google表格中转换货币
查看>>
wps表格日期计算天数_如何计算Google表格中两个日期之间的天数
查看>>
如何使Linux控制台更易于Linux新手使用
查看>>
谷歌浏览器开发文档获取书签_使用书签更快地浏览Word文档
查看>>
如何在Apple Watch上启用和使用缩放
查看>>
初学者:如何在Outlook 2010中向其他人分配任务
查看>>
windows 10 修复_如何修复Windows的10大烦恼
查看>>
系统映像恢复 进不了系统_如何从Windows系统映像中恢复特定文件
查看>>
如何学习Photoshop的极客指南,第2部分:面板
查看>>
如何在iPhone上将实时照片转换为视频或GIF
查看>>
xbmc_从iPhone或iPod Touch控制XBMC
查看>>
编程爱好者网站_读书爱好者的最佳免费网站
查看>>
为什么运行微波会杀死Wi-Fi连接?
查看>>
matlab生成文本乱码_如何生成完全随机/乱码文本的段落
查看>>
siri捷径调用谷歌翻译_告诉它使用Google助理,以减少Siri的麻烦
查看>>
outlook转发邮件步骤_Microsoft Outlook中的快速步骤指南
查看>>