This is a child of my other script
https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/NAT-table-fwx-alloc-top-users/m-p...
purely born for purpose of monitoring IP pool usage for our O365 NATs.
Idea is that you can display NAT stats for specific IPs instead of just top users like in my first script
Below is a partial screenshot for list o 16 NAT IPs:
Just update line inputIPs="1.2.3.4 5.6.7.8" with your own IPs separated by space
And switch to correct VSX context if you are using VSX
#!/bin/bash
source /opt/CPsuite-R80.30/fw1/scripts/vsenv.sh
# Script to interpret fwx_alloc table top users
# Only interpreting rows that start with TCP or UDP <00000006 or <00000011
# For VSX set to correct environment manually
# NAT pool does not take into considertaion dst port as per SK156852
inputIPs="1.2.3.4 5.6.7.8"
topcount=4 # Set how many top users to display
redthreshold=40000 # Highlight to show high usage
RED='\033[0;31m'
GRN='\033[0;32m'
CYN='\033[0;36m'
NC='\033[0m' # No Color
fw tab -t fwx_alloc -u > nat_table.raw
echo -e "${GRN}"
echo -e "==== TOTOAL COUNT PER IP ====${NC}"
echo -e "------------------------------"
for inputIP in ${inputIPs[@]}; do
# Get top NAT IPs
inputIPhex=`printf '%02x' ${inputIP//./ }; echo`
count=`cat nat_table.raw | sed 's/[><,;]//g' | egrep "^00000006|^00000011" | grep $inputIPhex | wc -l`
while [ ${#inputIP} -lt 20 ]; do inputIP="$inputIP "; done
echo -e " $inputIP $count"
done
echo; echo
for inputIP in ${inputIPs[@]}; do
echo -e "${GRN}"
echo -e "==== $inputIP DETAILS ====${NC}"
echo -e "------------------------------"
inputIPhex=`printf '%02x' ${inputIP//./ }; echo`
# Get top destination IPs
echo -e " TOP DST IP ADDRESSES"
echo -e " ------------------------------"
cat nat_table.raw | sed 's/[><,;]//g' | egrep "^00000006|^00000011" | grep $inputIPhex | awk '{print $4}' | sort | uniq -c | sort -r | head -$topcount | while read line; do
count=`echo "$line" | awk '{print $1}'`
ipaddr=`printf '%d.%d.%d.%d\n' $(echo $line | awk '{print $2}' | sed 's/../0x& /g')`
while [ ${#ipaddr} -lt 20 ]; do ipaddr="$ipaddr "; done
echo " $ipaddr $count"
done
echo
# Get top destination IPs
echo -e " TOP SRC IP ADDRESSES"
echo -e " ------------------------------"
cat nat_table.raw | sed 's/[><,;]//g' | egrep "^00000006|^00000011" | grep $inputIPhex | awk '{print $5}' | sort | uniq -c | sort -r | head -$topcount | while read line; do
count=`echo "$line" | awk '{print $1}'`
ipaddr=`printf '%d.%d.%d.%d\n' $(echo $line | awk '{print $2}' | sed 's/../0x& /g')`
while [ ${#ipaddr} -lt 20 ]; do ipaddr="$ipaddr "; done
echo " $ipaddr $count"
done
echo
done