OS/macOS

[OS/macOS] 패킷 트레이스 명령어

bbugge 2022. 7. 7. 14:38

/usr/bin or /usr/local/bin 에 실행권한주고 넣어서 사용

# /bin/bash
# ptrace
if [ ! -d /tmp/ptrace ];
then
mkdir /tmp/ptrace
fi

PTDIR=/tmp/ptrace
DATETIME=$(date +%Y%m%d%H%M%S)

COMMAND=$1

if [ -z $COMMAND ];
then
echo 'ERROR : Please input your command'
echo '[ trace / show / stop / help ]'
else
if [ "$COMMAND" = "help" ];
then
echo 'ptrace option [param]'
echo 'option : [ trace / show / stop ]'
elif [ "$COMMAND" = "trace" ];
then
if [ -z "$2" ];
                then
                        echo 'ERROR : Please input correct ethernet.'
                else
sudo -b tcpdump -i $2 -n > $PTDIR/trace_$DATETIME.log
                fi
elif [ "$COMMAND" = "show" ];
then
tail -f $PTDIR/`ls -ltr $PTDIR | tail -1 |awk '{print $9}'`
elif [ "$COMMAND" = "stop" ];
then
sudo kill -9 `ps -ef | grep ptrace | grep -v grep | awk '{print $2}'`
fi

fi