Thursday, October 8, 2020

tcpdump - capture files

Scripts

touch debug_start.sh 

#!/bin/bash
tcpdump  -s 0 -enni any  host 10.115.10.11  and port '(68 or 67)' -w  /home/admin/DHCP.pcap

touch debug_stop.sh 
killall tcpdump
#!/bin/bash

./debug_start.sh 
Keep the script running until we catch the dhcp failure
To stop the script run the debug_stop.sh
.debug_stop.sh

Expert@myvpn:0]# ls -lt DHCP.pcap
-rw-rw---- 1 admin root 24576 Oct  8 07:46 DHCP.pcap
 
[Expert@myvpn:0]# ps -aef | grep tcpdump
pcap      1857  1855  0 07:31 pts/6    00:00:00 tcpdump -s 0 -enni any host 10.115.1.11 and port (68 or
admin    12142 12024  0 07:48 pts/6    00:00:00 grep tcpdump
[Expert@myvpn:0]#
 
 

 

vpnd monitor

#! /bin/bash
#VPND Monitor
logfile="/var/log/vpnd_monitor.txt"
interval=7

while :
do
        vpnd=`pidof vpnd`
        echo "=========================================" >> $logfile
        echo "Date : `date`" >> $logfile
        echo "PID: $vpnd" >> $logfile
        echo Visitor mode table: `fw tab -t tcpt_external_ip -s | tail -1` >> $logfile
        echo "VPND open file descriptors: `ls -la /proc/$vpnd/fd | wc -l`" >> $logfile
        echo "Top 5 memory consumers:" >> $logfile
        echo "`ps -e -orss=,args=,%mem= | sort -b -k1,1nr | head -5`" >> $logfile
        echo "" >> $logfile

        echo "Top 5 CPU consumers:" >> $logfile
        echo "`ps -e -o pcpu,cpu,args | sort -b -k1,1nr | head -5`" >> $logfile
        echo "" >> $logfile

        echo "VPND CPU/memory usage:" >> $logfile
        echo "`ps -p $vpnd -o %cpu,%mem`" >> $logfile

        echo "================================" >> $logfile
        sleep 7
done