Explore our IP Address Database Downloads for instant access to our IP address insights
Learn moreThe 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.
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:
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:
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.
By gathering IPs from web request logs, teams can map visitor locations and analyze traffic patterns to gain insights into user behavior.
In environments with mixed IP versions, filtering out reserved and deprecated IPv6 addresses ensures only valid IPs are analyzed or counted.
Filtering IP addresses helps teams focus on critical data points while discarding irrelevant entries, making troubleshooting, security monitoring, and log analysis more efficient.
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.
Locate users, customize experiences, eliminate site risks, and use advanced filtering capabilities.
Before diving in, consider that there are at least two ways we know of for filtering IPs:
grep
with some complex regex.grepip
.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.
grepip
grepip
a specialized version of grep
specifically for IP filtering. It'll give us a bit more flexibility:
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.
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.
Choose from precise IP insights that scale from startups to enterprises.
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.
Abdullah leads the IPinfo internet data community and he also works on expanding IPinfo’s probe network of servers across the globe.