Name

ipset set listing wrapper script — Match and display ipset (netfilter.org) sets in various ways

Scope = security, networking, system administration -- linux - netfilter/ipset

Synopsis

ipset_list [ option [ option_argument ] ...] [ set-name-glob ...]

Files

/usr/sbin/ipset_list

/etc/ipset_list/ipset_list.conf

Description

ipset_list is a wrapper script for listing sets of the netfilter ipset program. It allows you to match and display sets, headers, and elements in various ways. The resulting representation of the query can be saved as shell script containing the set creation / population commands, or in ipset `save', or `xml' format.

It is written for the bash shell.

It includes an interactive wizard based mode, that utilizes a dialog program (dialog or whiptail are supported).

Optionally the output can be colorized.

A compspec (programmable completion specification) for bash completion is included.

Some variables are available inside the script configuration header, or the configuration file (ipset_list.conf). As the configuration file will be loaded after reading the configuration header, its settings take precedence. The variables are all undefined by default. Thus being available for manipulation in the environment at runtime. None of them is mandatory, unless you want to change default values. For details see section Environment, or the comments inside ipset_list[.conf].

Some options exclude or require each other. ipset_list will complain if that is the case. The output of ipset_list -h does display the valid combinations.

Example usage is given in the header of the script itself, or in the Readme.md shipping with ipset_list.

Options

All options are optional. Some require an argument, others do not. All options and their arguments must be separated by blank(s). If an option can be used more than once, it is mentioned explicitly.

When run without arguments, the names of all sets found, are displayed with the prefix `Name:'.

-h, -?

Show usage instructions.

-v

Show version information.

-

Enter interactive mode. This wizard based way to select the options utilizes a dialog program. Which can either be dialog or whiptail. dialog is the preferred and default, if the variable dialog_prog is not defined. Only dialog versions greater or equal to 1.2 are supported.

-a

Show all information (header and members) but with default delim (whitespace).

-c

Calculate the total amout of set members and also the sum of members matching a criteria given by another option.

-d delim

Delimiter character used to separate member entries. By default ipset uses newline as delimiter. ipset_list by default uses a whitespace. Which can be changed permanently by editing the variable delim in the configuration header of ipset_list.

If this parameter is used when starting interactive mode, it will apply globally to all search queries performed. Unless you choose the Delim option from the menu, which will overwrite the global value just for that single query.

-i

Show only the members of a single set.

-m

Show the set(s) members.

-n

Show the set names only. No prefix is shown, as when running ipset_list without arguments.

-r

Try to resolve ip addresses in the output (slow!).

If this option is used when entering interactive mode, it will be pre-selected in the menu, as long the session lasts.

-s

Print elements sorted (if supported by the set type).

If this option is used when entering interactive mode, it will be pre-selected in the menu, as long the session lasts.

-t

Show set headers only.

-Ca

Enable all counters (shortcut for -c -Cs -Ts -Tm).

-Co

Colorize the output.

Requires the cl program. It can be downloaded from here: http://sf.net/projects/colorize-shell/ or: https://github.com/AllKind/cl.

Configuration variables are available to adjust the color settings. Their names are prefixed with col_*. The list of valid color names can be retrieved by running cl --list.

The default is not to use colored output. That can be changed by setting the colorize variable to `1'.

If this option is used when entering interactive mode, it will be pre-selected in the menu, as long the session lasts.

-Cs

Count the amount of sets that matched the search criteria.

-Fg pattern

Match on members using a [ext]glob pattern.

-Fr pattern

Match on members using a regex pattern.

-Fh header-glob:value-glob [...]

Show sets containing one or more [ext]glob matching headers.

This option can be used multiple times.

-Fi header-glob:[!|<|>|<=|>=]value [...]

Show sets matching one or more integer valued header entries.

This option can be used multiple times.

-G

When in interactive mode, generate the ipset_list command-line, as for use in 'normal' mode.

If this option is used when entering interactive mode, then the option will be pre-selected in the menu, as long the session lasts.

-Gp [a[uto]|n[one]file]

Save the result of the query as shell script containing the ipset set creation / population commands.

If `auto' is used as option argument, the file name is automatically generated. Otherwise it must be specified.

If `none' is used as option argument, the output is sent to stdout. This will suppress normal output.

The option argument can be omitted. In that case `auto' is assumed.

The arguments `auto' and `none' can be written in short form. Meaning only the first character is mandatory. While `file' should be a regular file name.

It is not valid to use `-Gp none' together with `-Gs none', or `-Gx none'.

If this option is used when entering interactive mode, it will be preselected in the menu, as long the session lasts.

The directory the file(s) will be saved into can be modified using the cachedir variable.

-Gs [a[uto]|n[one]file]

Save the result of the query in `ipset save` output format.

Everything else is equal to option -Gp. See the above description.

-Gx [a[uto]|n[one]|file]

Save the result of the query as ipset xml output. The format is equal to the output of `ipset save -o xml`.

Everything else is equal to option -Gp. See the above description.

-Hi header-glob:[!|<|>|<=|>=]value [...]

Match on integer valued entries of the `Header' header. i.e. timeout.

This option can be used multiple times.

-Ht set-type-glob

Match on the set type.

-Hr [!|<|>|<=|>=]value

Match on number of references. value=integer.

-Hs [!|<|>|<=|>=]value

Match on size in memory. value=integer.

-Hv [!|<|>|<=|>=]value

Match on revision number. value=integer.

-Mc [!|<|>|<=|>=]value [...]

Match on the member count. value=integer.

-Oi option-glob:[!|<|>|<=|>=]value [...]

value = int | 0xhex[/0xhex] | hex:[!|<|>|<=|>=]hex.

Match values of member options. i.e. timeout.

This option can be used multiple times.

-T element [...]

Run `ipset test set element` to check if the element is in the set.

This option can be used multiple times.

-Tm

Calculate the total memory usage of all matching sets.

-To

Set timeout value (integer) in seconds for the shell builtin read. This affects the listing of sets. The default value of the set_tmout variable, which can be set in the configuration header of the script, is 30. This command line option overrides it.

If this parameter is used when starting interactive mode, it will apply globally to all search queries performed. Unless you choose the Timeout option from the menu, which will overwrite the global value just for that single search.

To influence for how long the result is displayed in interactive mode, before returning to the main screen, set the variable iactive_tmout (default 9999999999 - that should be sufficient time for you to stare at the result, aight?) to the desired value.

-Ts

Count the amount of traversed sets.

-Xo

Suppress the display of member options.

-Xh header-glob:value-glob [...]

Exclude one or more [ext]glob matching header entries.

This option can be used multiple times.

-Xg pattern

Exclude members matching a [ext]glob pattern.

-Xr pattern

Exclude members matching a regex pattern.

-Xs pattern [...]

Exclude sets matching a [ext]glob pattern.

This option can be used multiple times.

--

Stop further option processing.

Environment

The following variables are available during runtime. They can also be defined permanently in the configuration header of ipset_list, or the configuration file (ipset_list.conf).

config_file

The full path to the configuration file. This variable is obviously only available in the configuration header, or the environment.

ipset

Ipset executable. The variable can be either: empty, the name of the binary, or the full path to the binary.

cachedir

Directory to save the query results into. The variable can be either: empty, in which case it defaults to /var/cache/ipset_list, or a regular path.

set_tmout, iactive_tmout

See description of the `-To' parameter.

colorize

Colorize the output. The variable can be either: empty (=0), `0' - disabled, or `1' - enabled.

cl

The cl program. The variable can be either: empty, the name of the binary, or the full path to the binary. Also see description of the `-Co' parameter.

col_fg

Default foreground color. Defaults to white.

col_bg

Default background color. Defaults to black.

col_headers

Color for headers. Defaults to cyan.

col_members

Color for members. Defaults to yellow.

col_match

Color for matching entries. Defaults to red.

col_memsize

Color for displaying of memsize. Defaults to green.

col_set_count

Color for counting of matching sets. Defaults to magenta.

col_set_total

Color for counting of traversed sets. Defaults to blue.

col_highlight

General highlighting color. Defaults to white.

dialog_prog

The dialog program required for interactive mode. The variable can be either: empty, the name of the binary (dialog or whiptail), or the full path to the binary.

tput

The tput program - optional for interactive mode. The variable can be either: empty, the name of the binary, or the full path to the binary.

w_height

Terminal window height for interactive mode. Best practice is to set it to 0 and let tput retrieve the value.

w_with

Terminal window with for interactive mode. Best practice is to set it to 0 and let tput retrieve the value.

l_height

List height for interactive mode. Best practice is to set it to 0 and let ipset_list calculate the value (=w_height - 10).

Exit codes

An exit code of `0' indicates success. A return value of `1' is a good sign of failure. Usage errors will cause an exit value of `2'.

If a SIGNAL was received (HUP, INT, QUIT, STOP, TERM are trapped) the script exits with a return value of `111'.

See also

ipset(8) dialog(1) whiptail(1) bash(1) regex(7)