<?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: Export all rules referencing a list of IPs in Scripts</title>
    <link>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/72332#M793</link>
    <description>&lt;P&gt;&lt;FONT size="3"&gt;New version is available. I think this one is a pretty significant update.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="6"&gt;Changes&lt;/FONT&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;FONT size="3"&gt;Added CpmiGatewayPlain to the dereferencer.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="3"&gt;Updated most of my sed scripts to use ASCII Unit Separators rather than # for the field separation. This is important because Unit Separator is a non-printing character. It can't naturally occur in the comments of an object, which enables the next feature:&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="3"&gt;Added object comments to dereferencer output.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Wed, 15 Jan 2020 15:39:43 GMT</pubDate>
    <dc:creator>Bob_Zimmerman</dc:creator>
    <dc:date>2020-01-15T15:39:43Z</dc:date>
    <item>
      <title>IPs to Rules as JSON or CSV</title>
      <link>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/60341#M790</link>
      <description>&lt;P&gt;I recently had the need to build a table out of all of the rules referencing any IP address in a list of addresses. Basically a rule audit for all the rules involved in a given application.&lt;/P&gt;
&lt;P&gt;This post originally had several versions of the script attached directly, but I have since moved it to Github:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/Bob-Zimmerman/ipsToRulesCP" target="_blank" rel="nofollow noopener noreferrer"&gt;https://github.com/Bob-Zimmerman/ipsToRulesCP&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ipsToRules.png" style="width: 824px;"&gt;&lt;img src="https://community.checkpoint.com/t5/image/serverpage/image-id/11451iD3D930293461EF7C/image-size/large?v=v2&amp;amp;px=999" role="button" title="ipsToRules.png" alt="ipsToRules.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="6"&gt;USAGE&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;The script should be run as root (in expert mode, and with elevated privileges if you use low-privilege users) on the SmartCenter or MDS. Doesn't need any credentials. It does everything via the API in read-only mode.&lt;/P&gt;
&lt;P&gt;Usage is given right at the top of the script. It also prints the usage if you run the script with no switches or if you run it with the -h switch:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[Bob_Zimmerman@MySmartCenter]# ./ipsToRules.sh -h
Usage:
./ipsToRules.sh [-d] [-h] [-J file] [-j file] [-c file] [-O] 
Default output is pretty-print JSON to STDOUT, suitable for output redirection.
	-d		Increase debug level, up to twice.
	-h		Print this usage information.
	-J file	Write pretty-print JSON output to .
	-j file	Write compact JSON output to . One line per rule.
	-c file	Write quote-delimited CSV output to .
	-O		Write pretty-print JSON output to STDOUT.
	list	List of IPs to search for, separated by spaces.&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see, it currently has options for compact JSON output, pretty JSON output, and quote-delimited CSV output. It should be pretty clear from the code how to write a new output formatter. Just needs a new variable for the name, a new switch in the getopts case statement, a little output prep work, and a new item in the "masterOutput" function.&lt;/P&gt;
&lt;P&gt;The only privileged commands it uses right now are 'cpprod_util FwIsFirewallMgmt' (to detect if it is run on a firewall instead of a management) and 'mdsstat' (to detect if it is a SmartCenter or MDS), within a few lines of each other at the bottom. You can make a version which will work only on a SmartCenter or only on an MDS, and it would work as an unprivileged user.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="6"&gt;KNOWN LIMITATIONS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;It currently accepts only IP addresses. Haven't yet gotten around to writing logic for spotting CIDR notation, or for looking up networks once I've found them in the input.&lt;/P&gt;
&lt;P&gt;There's a big case statement in the middle for dereferencing objects. It includes all the object types I personally needed, but I'm sure there are plenty which are not included.&lt;/P&gt;
&lt;P&gt;I'm pretty sure there are error cases I don't handle properly, such as if none of the IP addresses are found.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 13:20:27 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/60341#M790</guid>
      <dc:creator>Bob_Zimmerman</dc:creator>
      <dc:date>2021-04-21T13:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: Export all rules referencing a list of IPs</title>
      <link>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/60778#M791</link>
      <description>&lt;P&gt;New version is available.&lt;/P&gt;&lt;P&gt;&lt;FONT size="6"&gt;CHANGES&lt;/FONT&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Added object UID output to dereferencer failures to help find the object in question and write a new dereferencer case.&lt;/LI&gt;&lt;LI&gt;Added four object types to the object dereferencer (service-other, CpmiHostCkp, address-range, Internet).&lt;/LI&gt;&lt;LI&gt;Normalized multi-line pipeline styling.&lt;/LI&gt;&lt;LI&gt;Fixed object dereferencer handling for spaces in object names.&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Tue, 20 Aug 2019 20:18:32 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/60778#M791</guid>
      <dc:creator>Bob_Zimmerman</dc:creator>
      <dc:date>2019-08-20T20:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: Export all rules referencing a list of IPs</title>
      <link>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/70464#M792</link>
      <description>&lt;P&gt;New version is available.&lt;/P&gt;&lt;P&gt;&lt;FONT size="6"&gt;CHANGES&lt;/FONT&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Rearranged dereferencer objects to case-insensitive alphabetical order.&lt;/LI&gt;&lt;LI&gt;Added more types to the dereferencer (group-with-exclusion, service-dce-rpc)&lt;/LI&gt;&lt;LI&gt;Added basic object output for dereferencer failures.&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Fri, 13 Dec 2019 20:56:04 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/70464#M792</guid>
      <dc:creator>Bob_Zimmerman</dc:creator>
      <dc:date>2019-12-13T20:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: Export all rules referencing a list of IPs</title>
      <link>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/72332#M793</link>
      <description>&lt;P&gt;&lt;FONT size="3"&gt;New version is available. I think this one is a pretty significant update.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="6"&gt;Changes&lt;/FONT&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;FONT size="3"&gt;Added CpmiGatewayPlain to the dereferencer.&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="3"&gt;Updated most of my sed scripts to use ASCII Unit Separators rather than # for the field separation. This is important because Unit Separator is a non-printing character. It can't naturally occur in the comments of an object, which enables the next feature:&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;&lt;FONT size="3"&gt;Added object comments to dereferencer output.&lt;/FONT&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Wed, 15 Jan 2020 15:39:43 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/72332#M793</guid>
      <dc:creator>Bob_Zimmerman</dc:creator>
      <dc:date>2020-01-15T15:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Export all rules referencing a list of IPs</title>
      <link>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/82053#M794</link>
      <description>&lt;P&gt;I have decided to start pushing this script to Github:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Bob-Zimmerman/ipsToRulesCP" target="_blank"&gt;https://github.com/Bob-Zimmerman/ipsToRulesCP&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I will try to share major changes here, but smaller changes will only show up there. If you look at the commit history, you may see I have broken down the changes in a more granular way than I did here. The prior batches of changes were to avoid forum noise by only posting when I felt there were somewhat significant updates. Version control systems like Git, however, are really built with the idea of small, focused changes. That is the model I will be using in the future.&lt;/P&gt;&lt;P&gt;As an added benefit, now I get an issue tracker, and other people can send proposed changes more easily.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Apr 2020 22:00:38 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/82053#M794</guid>
      <dc:creator>Bob_Zimmerman</dc:creator>
      <dc:date>2020-04-15T22:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: Export all rules referencing a list of IPs</title>
      <link>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/116364#M795</link>
      <description>&lt;P&gt;&lt;a href="https://community.checkpoint.com/t5/user/viewprofilepage/user-id/181"&gt;@_Val_&lt;/a&gt;&amp;nbsp;looks like a Toolbox addition.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Apr 2021 20:57:41 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/116364#M795</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2021-04-19T20:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Export all rules referencing a list of IPs</title>
      <link>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/116524#M796</link>
      <description>&lt;P&gt;Actually, this reminded me. Some time last year, I did get around to testing whether you can make a cyclic set of groups (group A contains group B, group B contains group A), and confirmed the management won't let you. Removed that concern from the known limitations!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 13:22:37 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Scripts/IPs-to-Rules-as-JSON-or-CSV/m-p/116524#M796</guid>
      <dc:creator>Bob_Zimmerman</dc:creator>
      <dc:date>2021-04-21T13:22:37Z</dc:date>
    </item>
  </channel>
</rss>

