码迷,mamicode.com
首页 > 其他好文 > 详细

如何对远程主机捕包并在本地wireshark显示?

时间:2019-12-06 19:41:19      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:使用方法   options   rem   sudo   wireshark   pdu   get   std   remote   

脚本如下:

#!/usr/bin/env bash
[[ -n $DEBUG ]] && set -x
# set -eou pipefail

useage(){
  cat <<"EOF"
USAGE:
    hostdump.sh TARGET IFACE [OPTIONS...]
EOF
}

exit_err() {
   echo >&2 "${1}"
   exit 1
}

if [ $# -lt 2 ];then
    useage
    exit 1
fi

LOCAL_TCPDUMP=/usr/local/bin/static-tcpdump
REMOTE_TCPDUMP=/tmp/static-tcpdump
TARGET=$1
IFACE=$2
shift 2
if sshpass -e "${TARGET}" [[ ! -f "${REMOTE_TCPDUMP}" ]];then
  sshpass -e scp "${LOCAL_TCPDUMP}"  "${TARGET}":"${REMOTE_TCPDUMP}"
fi
sshpass -e ssh "${TARGET}" "${REMOTE_TCPDUMP}" -i "${IFACE}" -s 0 -U -w - $@ | /bin/sh -c "sudo wireshark -k -i -"

使用方法

准备静态编译的tcpdump

配置好~/.ssh/config

Host host1
    Hostname 192.168.1.100
    User root
hostdump.sh host1 eth0

如何对远程主机捕包并在本地wireshark显示?

标签:使用方法   options   rem   sudo   wireshark   pdu   get   std   remote   

原文地址:https://www.cnblogs.com/futuretea/p/11996868.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!