IPinfo CLI bulk command: Filter Bogon IP addresses with JQ

JQ is a command line tool for processing and manipulating JSON data.

:link: jq

JQ is one of the tools that complement our CLI really well. With JQ you can extend our CLI’s abilities.

bulk command crash course

The CLI’s bulk command can run bulk IP lookup operations from a list of IP addresses. You can pass an IP range, a CIDR, and a list of IPs and pipe IP addresses as input. The command supports both CSV and JSON output.

ipinfo bulk ips.txt
Usage: ipinfo bulk [<opts>] <ip | ip-range | cidr | filepath>

  Accepts IPs, IP ranges, CIDRs and file paths.

  # Lookup all IPs from stdin ('-' can be implied).
  $ ipinfo prips | ipinfo bulk
  $ ipinfo prips | ipinfo bulk -

  # Lookup all IPs in 2 files.
  $ ipinfo bulk /path/to/iplist1.txt /path/to/iplist2.txt

  # Lookup all IPs from CIDR.
  $ ipinfo bulk

  # Lookup all IPs from multiple CIDRs.
  $ ipinfo bulk

  # Lookup all IPs in an IP range.
  $ ipinfo bulk

  # Lookup all IPs from multiple sources simultaneously.
  $ ipinfo bulk ips.txt

    --token <tok>, -t <tok>
      use <tok> as API token.
      do not use the cache.
    --help, -h
      show help.

    --field <field>, -f <field>
      lookup only specific fields in the output.
      field names correspond to JSON keys, e.g. 'hostname' or 'company.type'.
      multiple field names must be separated by commas.
      disable colored output.

    --json, -j
      output JSON format. (default)
    --csv, -c
      output CSV format.

Why you might need to do Bogon filtering.

Some IP addresses and IP ranges are reserved for special use, such as for local or private networks, and should not appear on the public internet. These reserved ranges, along with other IP ranges that haven’t yet been allocated and shouldn’t appear on the public internet, are sometimes known as bogons.

Source: Bogon IP Address Ranges - IPinfo.io

If you are running IP log data enrichment or running our grepip command, you will come across bogon IP addresses that do not have any IP data information associated with them. They can sometimes be distracting, so we might need to filter them out.

Filtering out bogon IP addresses from the CLI bulk command

My IP address list:


Command to filter out bogon IPs:

ipinfo bulk ips_email.txt | jq 'to_entries | map(select(.value.bogon != true)) | from_entries'


JQ function breakdown:

  • to_entries convert the input to a key-value like pairs
  • map(select(.value.bogon != true)) Uses a combination of map and select command to find out which element does not have the bogon field as not true aka false.
  • form_entries convert the key-value like pairs to the original JSON object.