# IPinfo CLI bulk command: Filter Bogon IP addresses with JQ

**URL:** <https://community.ipinfo.io/t/ipinfo-cli-bulk-command-filter-bogon-ip-addresses-with-jq/1509>\
**Category:** General\
**Tags:** cli\
**Created:** [July 10, 2023, 6:18pm UTC](https://community.ipinfo.io/t/ipinfo-cli-bulk-command-filter-bogon-ip-addresses-with-jq/1509 "2023-07-10T18:18:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abdullah](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.ipinfo.io/abdullah/32/4973_2.png) [@Abdullah](https://community.ipinfo.io/u/Abdullah)\
**Post date:** [July 10, 2023, 6:18pm UTC](https://community.ipinfo.io/t/ipinfo-cli-bulk-command-filter-bogon-ip-addresses-with-jq/1509/1 "2023-07-10T18:18:41Z")

</div>

[JQ](https://jqlang.github.io/jq/) is a command line tool for processing and manipulating JSON data.

 ![Filter Bogon IP addresses with JQ](https://canada1.discourse-cdn.com/flex035/uploads/ipinfo/original/2X/2/2c7bec5ae772f5a97ca3b347b38ff1cedff49d09.png)

### 🔗 [jq](https://jqlang.github.io/jq/)

JQ is one of the tools that complement our [CLI](https://github.com/ipinfo/cli) really well. With JQ you can extend our [CLI](https://github.com/ipinfo/cli)’s abilities.

## `bulk` command crash course

The [CLI](https://github.com/ipinfo/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.

```bash
ipinfo bulk ips.txt

```

> **Manual**
>
> ```plaintext
> Usage: ipinfo bulk [<opts>] <ip | ip-range | cidr | filepath>
> 
> Description:
> Accepts IPs, IP ranges, CIDRs and file paths.
> 
> Examples:
> # Lookup all IPs from stdin ('-' can be implied).
> $ ipinfo prips 8.8.8.0/24 | ipinfo bulk
> $ ipinfo prips 8.8.8.0/24 | 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 8.8.8.0/24
> 
> # Lookup all IPs from multiple CIDRs.
> $ ipinfo bulk 8.8.8.0/24 8.8.2.0/24 8.8.1.0/24
> 
> # Lookup all IPs in an IP range.
> $ ipinfo bulk 8.8.8.0-8.8.8.255
> 
> # Lookup all IPs from multiple sources simultaneously.
> $ ipinfo bulk 8.8.8.0-8.8.8.255 1.1.1.0/30 123.123.123.123 ips.txt
> 
> Options:
> General:
> --token <tok>, -t <tok>
> use <tok> as API token.
> --nocache
> do not use the cache.
> --help, -h
> show help.
> 
> Outputs:
> --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.
> --nocolor
> disable colored output.
> 
> Formats:
> --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](https://ipinfo.io/countries). 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: [https://ipinfo.io/bogon](https://ipinfo.io/bogon)

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:

> ips\_email.txt

```auto
023.07.10.04
2002:a0d:cad6:0:b0:576:94e1:efec
2002:a0d:cc8e:0:b0:57a:2250:f5c0
2002:a5d:6047:0:0:0:0:0
209.85.220.73
::

```

Command to filter out bogon IPs:

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

```

Output:

 ![The output of filtered bulk IP addresses](https://canada1.discourse-cdn.com/flex035/uploads/ipinfo/original/2X/5/5f215ce10aa456dc2314e7a5b84f85ff4cfb0693.png)

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.
