<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: NAT table (fwx_alloc) specific NAT IP address analyses in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/NAT-table-fwx-alloc-specific-NAT-IP-address-analyses/m-p/98563#M5211</link>
    <description>&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;+1&lt;/FONT&gt;&lt;/STRONG&gt; Kaspars for Champion! &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Oct 2020 14:23:57 GMT</pubDate>
    <dc:creator>Danny</dc:creator>
    <dc:date>2020-10-08T14:23:57Z</dc:date>
    <item>
      <title>NAT table (fwx_alloc) specific NAT IP address analyses</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/NAT-table-fwx-alloc-specific-NAT-IP-address-analyses/m-p/89644#M4978</link>
      <description>&lt;P&gt;This is a child of my other script&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/NAT-table-fwx-alloc-top-users/m-p/87260#M4936" target="_blank" rel="noopener"&gt;https://community.checkpoint.com/t5/API-CLI-Discussion-and-Samples/NAT-table-fwx-alloc-top-users/m-p/87260#M4936&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;purely born for purpose of monitoring IP pool usage for our O365 NATs.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Idea is that you can display NAT stats for specific IPs instead of just top users like in my first script&lt;/P&gt;
&lt;P&gt;Below is a partial screenshot for list o 16 NAT IPs:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="image.png" style="width: 467px;"&gt;&lt;img src="https://community.checkpoint.com/t5/image/serverpage/image-id/6981i6DA01D30C3812A24/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Just update line inputIPs="1.2.3.4 5.6.7.8" with your own IPs separated by space&lt;/P&gt;
&lt;P&gt;And switch to correct VSX context if you are using VSX&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#!/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 &amp;lt;00000006 or &amp;lt;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 &amp;gt; 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/[&amp;gt;&amp;lt;,;]//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/[&amp;gt;&amp;lt;,;]//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&amp;amp; /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/[&amp;gt;&amp;lt;,;]//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&amp;amp; /g')`
    while [ ${#ipaddr} -lt 20 ]; do ipaddr="$ipaddr "; done
    echo "     $ipaddr $count"
  done
  echo

done
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2021 09:20:13 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/NAT-table-fwx-alloc-specific-NAT-IP-address-analyses/m-p/89644#M4978</guid>
      <dc:creator>Kaspars_Zibarts</dc:creator>
      <dc:date>2021-02-19T09:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: NAT table (fwx_alloc) specific NAT IP address analyses</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/NAT-table-fwx-alloc-specific-NAT-IP-address-analyses/m-p/89657#M4979</link>
      <description>&lt;P&gt;Cool. Thanks Kaspars!&lt;/P&gt;
&lt;P&gt;I suggest changing the env sourcing to:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;source /etc/profile.d/CP.sh
if [[ -e /etc/profile.d/vsenv.sh ]]; then
    source /etc/profile.d/vsenv.sh
fi&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 24 Jun 2020 08:12:18 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/NAT-table-fwx-alloc-specific-NAT-IP-address-analyses/m-p/89657#M4979</guid>
      <dc:creator>Danny</dc:creator>
      <dc:date>2020-06-24T08:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: NAT table (fwx_alloc) specific NAT IP address analyses</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/NAT-table-fwx-alloc-specific-NAT-IP-address-analyses/m-p/89666#M4980</link>
      <description>Thanks Danny!</description>
      <pubDate>Wed, 24 Jun 2020 09:02:30 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/NAT-table-fwx-alloc-specific-NAT-IP-address-analyses/m-p/89666#M4980</guid>
      <dc:creator>Kaspars_Zibarts</dc:creator>
      <dc:date>2020-06-24T09:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: NAT table (fwx_alloc) specific NAT IP address analyses</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/NAT-table-fwx-alloc-specific-NAT-IP-address-analyses/m-p/98560#M5210</link>
      <description>&lt;P&gt;Adding per core version:&lt;/P&gt;
&lt;DIV id="tinyMceEditor_78397e5e612d5eKaspars_Zibarts_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="2020-10-08_16-17-54.jpg" style="width: 409px;"&gt;&lt;img src="https://community.checkpoint.com/t5/image/serverpage/image-id/8324i6137449EAA02870A/image-size/large?v=v2&amp;amp;px=999" role="button" title="2020-10-08_16-17-54.jpg" alt="2020-10-08_16-17-54.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;#!/bin/bash
source /etc/profile.d/CP.sh
if [[ -e /etc/profile.d/vsenv.sh ]]; then
    source /etc/profile.d/vsenv.sh
fi

RED='\033[0;31m'
GRN='\033[0;32m'
CYN='\033[0;36m'
NC='\033[0m' # No Color

vsenv 6   # For VS on VSX
topcount=3  # Set pools to show

corexlcount=`fw ctl multik stat | wc -l`
let corexlcount=corexlcount-2

i=0
while [ $i -lt $corexlcount ]; do
  totalcount=`wc -l nat_table.raw | awk '{print $1}'`
  echo -e "${GRN}"
  echo -e "=== Core-$i Total count: $totalcount ===${NC}"
  echo -e "-----------------------------------------------"

  fw -i $i tab -t fwx_alloc -u &amp;gt; nat_table.raw

  cat nat_table.raw | sed 's/[&amp;gt;&amp;lt;,;]//g' | egrep "^00000006|^00000011" | awk '{print $1" "$2" "$4}' | sort -k1 -k2 -k3 | uniq -c |  sort -r | head -$topcount | while read line; do

    count=`echo "$line" | awk '{print $1}'`
    if [ $count -gt 8200 ]; then count="${RED}${count}"; fi

    proto="TCP"
    if [ `echo $line | awk '{print $2}' | grep -c "00000006"` -eq 0 ]; then proto="UDP"; fi


    natIPhex=`echo $line | awk '{print $3}'`
    dstIPhex=`echo $line | awk '{print $4}'`
    natIP=`printf '%d.%d.%d.%d\n' $(echo $line | awk '{print $3}' | sed 's/../0x&amp;amp; /g')`
    dstIP=`printf '%d.%d.%d.%d\n' $(echo $line | awk '{print $4}' | sed 's/../0x&amp;amp; /g')`
    while [ ${#natIP} -lt 15 ]; do natIP="$natIP "; done
    while [ ${#dstIP} -lt 15 ]; do dstIP="$dstIP "; done
    echo -e "${CYN}  $proto $natIP &amp;gt; $dstIP  : $count${NC}"
  done
  let i++
  echo
done
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 08 Oct 2020 14:21:44 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/NAT-table-fwx-alloc-specific-NAT-IP-address-analyses/m-p/98560#M5210</guid>
      <dc:creator>Kaspars_Zibarts</dc:creator>
      <dc:date>2020-10-08T14:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: NAT table (fwx_alloc) specific NAT IP address analyses</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/NAT-table-fwx-alloc-specific-NAT-IP-address-analyses/m-p/98563#M5211</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;+1&lt;/FONT&gt;&lt;/STRONG&gt; Kaspars for Champion! &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 14:23:57 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/NAT-table-fwx-alloc-specific-NAT-IP-address-analyses/m-p/98563#M5211</guid>
      <dc:creator>Danny</dc:creator>
      <dc:date>2020-10-08T14:23:57Z</dc:date>
    </item>
  </channel>
</rss>

