Explore our IP Address Database Downloads for instant access to our IP address insights

Learn more
16 days ago by Abdullah 5 min read

How to Filter IPs with IPinfo CLI

 How to Filter IPs

The ability to filter IPs is invaluable for efficiently managing large datasets of IP addresses for various applications, such as network security, data analysis, and marketing.

Our official IPinfo CLI includes features ranging from bulk lookups to summarizing details for up to 1000 IPs, allowing users to query our APIs more quickly. Our CLI also includes a handy command called grepip that enables users to filter multiple IP addresses so they can quickly sift through logs, text files, or data streams to identify relevant IP addresses.

Example Scenarios for IP Filtering and Grepip Use Cases

Grepip helps find IPs in arbitrarily large texts and can also help clean up an IP list into usable datasets. Here are several use cases of grepip:

  1. View all IPs after scraping a web page with IP content.
  2. Gather all IPs in a web request log to put onto a map to see where our web users come from.
  3. Retrieve only IPv6 addresses in a list containing a huge variety of IP addresses and count how many there are.
  4. Exclude bogon IP addresses (private IP address, reserved IPs etc.).
  5. Retrieve both CIDRs and IP address ranges.
  6. Use data filters to see only the most relevant IPs.

In other words, you can use grepip to make lists of IP addresses more accessible and flexible. Learn more about how to optimize IP data.

The grepip command simplifies filtering IPs from large datasets, making data management more efficient. Here are real-world applications showcasing how different teams can benefit from IP filtering with IPinfo’s CLI:

1. Filter Non-Bogon IPs After Scraping Web Pages

When working with scraped IP data from web pages, filtering out non-bogon IPs ensures only legitimate and publicly routable IPs remain. This prevents the processing of invalid or unusable addresses.

  • Cybersecurity teams: Identify valid IPs while discarding bogon addresses to reduce false positives during threat detection.
  • Data engineers: Pre-process scraped IP datasets by removing private and reserved IPs before further analysis.
  • API developers: Filter out invalid requests by removing bogon IPs in incoming API logs, improving app security.

2. Map Web Users by IP From Request Logs

By gathering IPs from web request logs, teams can map visitor locations and analyze traffic patterns to gain insights into user behavior.

  • Marketing analysts: Pinpoint where visitors are located and launch region-specific campaigns based on IP geolocation data.
  • Product managers: Use traffic origin data to prioritize language localization and country-specific feature development.
  • Compliance officers: Track traffic sources to meet data residency regulations and improve legal compliance tracking.

3. Isolate Non-Bogon IPv6 Addresses in Large IP Lists

In environments with mixed IP versions, filtering out reserved and deprecated IPv6 addresses ensures only valid IPs are analyzed or counted. 

  • Network engineers: Manage IPv6 capacity by filtering out inactive or bogon IPv6 addresses for better network provisioning.
  • Research analysts: Study traffic trends and IP usage patterns for product development or academic research.
  • Data analysts: Create clean, reliable datasets by removing unnecessary IP ranges and improving report accuracy.

4. Use Data Filters to Focus on Relevant IPs

Filtering IP addresses helps teams focus on critical data points while discarding irrelevant entries, making troubleshooting, security monitoring, and log analysis more efficient.

  • IT & devOps teams: Isolate IP logs for quick troubleshooting during incidents or system performance monitoring.
  • Threat intelligence teams: Flag high-risk IPs using predefined filters, enhancing threat detection efforts.
  • Web administrators: Block unwanted traffic while ensuring access for legitimate users, providing a better site experience.

As you can see, filtering IP addresses is essential for transforming raw data into actionable insights, making it a critical step across various applications. Whether you’re mapping user locations, securing your network, or managing large IP lists, accurate IP filtering supports better decision-making and operational efficiency. With grepip, teams can focus on extracting valuable insights while leaving complex filtering tasks to a reliable, purpose-built tool.

In other words, you can use grepip to make lists of IP addresses more accessible and flexible. Learn more about how to optimize IP data.

Get started with IPinfo’s trusted API

Locate users, customize experiences, eliminate site risks, and use advanced filtering capabilities.

Sign Up for Free

How to Filter IPs

0:00
/0:18

The step-by-step process for filtering IPs

Filtering IPs

Before diving in, consider that there are at least two ways we know of for filtering IPs:

  1. Use grep with some complex regex.
  2. Use grepip.

Using grep

With grep, here's a regex that will get the job done most of the time:

$ ip addr | grep -E -o '([0-9]{1,3}\.){3}[0-9]{1,3}'
127.0.0.1
111.111.111.111
192.168.8.101
192.168.8.255

The problem is, this matches with 999.999.999.999 as well, which is not a valid IPv4 address.

Here's another one that's going to exclude strings whose numbers are out-of-range:

$ ip addr | grep -E -o '((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
127.0.0.1
111.111.111.111
192.168.8.101
192.168.8.255

You can alias this to make it easier to access:

$ alias grepipv4="grep -E -o '((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'"
$ ip addr | grepipv4
127.0.0.1
111.111.111.111
192.168.8.101
192.168.8.255

The problem is, if you want to change the options, you'd have to type it manually anyway or create a bash function instead of an alias.

Using grepip

grepip a specialized version of grep specifically for IP filtering. It'll give us a bit more flexibility:

  • No regex needed.
  • Can filter IPv6 addresses simultaneously as well.
  • Can filter out reserved/bogon IP addresses.

If you don't have it, first install it:

# using homebrew?
$ brew install grepip

# using debian/ubuntu?
$ curl -Ls https://github.com/ipinfo/cli/releases/download/grepip-1.1.0/deb.sh | sh

# using go get?
$ go get github.com/ipinfo/cli/grepip

# something else? see https://github.com/ipinfo/cli#installation

Let's see how to do the same IPv4 filtering as above with grepip

$ ip addr | grepip -o -4 127.0.0.1 111.111.111.111 192.168.8.101 192.168.8.255

If we wanted to only know about non-reserved IPs, just use the -x or --exclude-reserved flag:

$ ip addr | grepip -o -4 127.0.0.1 111.111.111.111 192.168.8.101 192.168.8.255

If you remove the -4 flag which forces only IPv4 filtering, you can get IPv6 matches as well.

Type grepip --help for more details.

All CLI binaries (e.g. ipinfo, grepip) are available for download from multiple mechanisms. See https://github.com/ipinfo/cli#installation for full details.

Getting Started With IPinfo's CLI

Filtering IP addresses efficiently is crucial for making sense of vast datasets and unlocking their full potential. Tools like grepip streamline the process, allowing users to extract and focus on the most relevant IP data with precision and speed.

However, filtering is just the beginning. Choosing the right IP provider to complement your efforts is key to transforming raw IP data into actionable insights. With its industry-leading IP data, available in API or database IP format, IPinfo provides the IP accuracy and meaningful context you need to target the right audiences, secure your network, and optimize your strategies. 

Ready to elevate your IP data game? Make IPinfo your trusted partner for reliable, powerful IP intelligence.

Want flexible pricing for the most accurate IP data?

Choose from precise IP insights that scale from startups to enterprises.

API Access Pricing

IPinfo is a comprehensive IP address data and API provider with flexible pricing plans to meet your business needs. We handle billions of API requests per month, serving data like IP geolocation, VPN detection, ASN, and more. Sign up for a free account or contact our team to learn more.

This blog was last updated on 1/6/2025: We regularly update our blog posts to ensure they reflect the most current information.

About the author

Abdullah

Abdullah

Abdullah leads the IPinfo internet data community and he also works on expanding IPinfo’s probe network of servers across the globe.