shell每隔一秒钟就记录下netstat状态
Posted 17bdw
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell每隔一秒钟就记录下netstat状态相关的知识,希望对你有一定的参考价值。
说明
木马可能类似随机发送心跳包的操作,随机sleep。对这类情况写好了一个监听shell脚本,每隔一秒钟就记录下netstat状态。
代码
#!/bin/bash
#功能:用于定时执行lsof 和 netstat 的执行状态并记录到文件
slptime=1 #默认一秒执行一次
filedir=/tmp #默认存储在/tmp下
lsoffile=lsof.log #存储lsof的执行结果
netstatfile=netstatfile.log #存储netstat执行结果
while true
do
sleep $slptime
date=$(date '+%Y-%m-%d %H:%M:%S')
echo $date":" >> $filedir/$lsoffile
echo $date":" >> $filedir/$netstatfile
lsof -i >> $filedir/$lsoffile
netstat -tunlp >> $filedir/$netstatfile
done
以上是关于shell每隔一秒钟就记录下netstat状态的主要内容,如果未能解决你的问题,请参考以下文章