#!/bin/bash
# This is to get input about port number and IPs
printf "What local port number do you want to see about a current SCTP path(port number only): "
read portNumber
printf "What is primary local IPs : "
read lpIP
printf "What is secondary local IPs : "
read lsIP
printf "What is primary remote IPs : "
read rpIP
printf "What is secondary remote IPs : "
read rsIP
# This is to remove files which this scripts is using
rm -f tcpdumpResult awkResult1 awkResult2 rlpIP rlsIP rrpIP rrsIP
# This is to run TCPDUMP to catch SCTP path
timeout 30 tcpdump -i any -n port $portNumber | grep -v ethertype >> tcpdumpResult
# This is to fetch local IP from the tcpdump result
awk '{print $3}' tcpdumpResult >> awkResult1
# This is to fetch remote IP from the tcpdump result
awk '{print $5}' tcpdumpResult >> awkResult2
# This is to count local primary IP and write the number in rlpIP file
grep -o -i $lpIP awkResult1 | wc -l >> ./rlpIP
# This is to count local secondary IP and write the number in rlsIP file
grep -o -i $lsIP awkResult1 | wc -l >> ./rlsIP
# This is to count remote primary IP and write the number in rrpIP file
grep -o -i $rpIP awkResult2 | wc -l >> ./rrpIP
# This is to count remote secondary IP and write the number in rrsIP file
grep -o -i $rsIP awkResult2 | wc -l >> ./rrsIP
# This is to put the number rlpIP into variable
export rlpIP=`cat ./rlpIP`
export rlsIP=`cat ./rlsIP`
export rrpIP=`cat ./rrpIP`
export rrsIP=`cat ./rrsIP`
# This is to compare counts between the primary with secondary IPs for Local
if [ $rlpIP -gt $rlsIP ]
then
echo "The current SCTP LOCAL IP: $lpIP"
else
echo "The current SCTP LOCAL IP: $lsIP"
fi
# This is to compare counts between the primary with secondary IPs for remote
if [ $rrpIP -gt $rrsIP ]
then
echo "The current SCTP REMOTE IP: $rpIP"
else
echo "The current SCTP REMOTE IP: $rsIP"
fi
# This is to remove files which this scripts used
rm -f tcpdumpResult awkResult1 awkResult2 rlpIP rlsIP rrpIP rrsIP
exit 0