Showing results for 
Search instead for 
Did you mean: 
Create a Post

Export all rules referencing a list of IPs

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.


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.

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:


[Bob_Zimmerman@MySmartCenter]# ./ -h
./ [-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.



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.

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.


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.

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.

I'm pretty sure there are error cases I don't handle properly, such as if none of the IP addresses are found.

I don't know if you can build a cycle of groups (as an example, group A contains group B, group B contains group C, group C contains group A), but I don't do any detection for that.

4 Replies

Re: Export all rules referencing a list of IPs

New version is available.


  • Added object UID output to dereferencer failures to help find the object in question and write a new dereferencer case.
  • Added four object types to the object dereferencer (service-other, CpmiHostCkp, address-range, Internet).
  • Normalized multi-line pipeline styling.
  • Fixed object dereferencer handling for spaces in object names.

Re: Export all rules referencing a list of IPs

New version is available.


  • Rearranged dereferencer objects to case-insensitive alphabetical order.
  • Added more types to the dereferencer (group-with-exclusion, service-dce-rpc)
  • Added basic object output for dereferencer failures.

Re: Export all rules referencing a list of IPs

New version is available. I think this one is a pretty significant update.


  • Added CpmiGatewayPlain to the dereferencer.
  • 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:
  • Added object comments to dereferencer output.
0 Kudos

Re: Export all rules referencing a list of IPs

I have decided to start pushing this script to Github:

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.

As an added benefit, now I get an issue tracker, and other people can send proposed changes more easily.

0 Kudos