Splunk Search

group IP by CIDR range in results

jeff
Contributor

I am trying to find a way to turn an IP address into CIDR format to group by reports. Ideally, I'd be able to do something like:

eval ip_sub=ciderize(ip,25)

So, for instance, an address of 172.20.66.54 in the forumla above would return 172.20.66.0/25, while 172.30.66.195 would return a value of 172.20.66.128/25.

I know I could do it with a lookup table if the number of ranges were known/small, but I'm trying to have some level of grouping for external IP addresses in our firewall logs. Maybe I'm just missing something obvious?

Tags (3)
0 Karma
1 Solution

Stephen_Sorkin
Splunk Employee
Splunk Employee

Your approach of using a lookup is good, but I'd suggest a scripted lookup rather than a static CSV lookup (alternately you could use a custom search command; a discussion of the differences are at http://splunk-base.splunk.com/answers/3890/pros-and-cons-external-lookup-script-vs-custom-search-com...).

If you were to use a lookup, the contract the script would advertise is simple, it is presented three columns corresponding to IP address, one for the number of bits and one for the CIDR address, typically with the CIDR address left blank. Its task would be to fill out that column. For simplicity, you might want to make one lookup function and 32 lookup tables in transforms.conf, each which sends the number of bits to the script, so that you only have to provide two columns.

A search command could do the same thing.

View solution in original post

0 Karma

cvajs
Contributor

just for clarity, the question is not 100% accurate from a mask syntax perspective. a IP in a subnet, in CIDR syntax, comes out as IP/mask, not Network/mask. the problem is how to return the Network (aka subnet) in CIDR syntax for any given IP.

0 Karma

Stephen_Sorkin
Splunk Employee
Splunk Employee

Your approach of using a lookup is good, but I'd suggest a scripted lookup rather than a static CSV lookup (alternately you could use a custom search command; a discussion of the differences are at http://splunk-base.splunk.com/answers/3890/pros-and-cons-external-lookup-script-vs-custom-search-com...).

If you were to use a lookup, the contract the script would advertise is simple, it is presented three columns corresponding to IP address, one for the number of bits and one for the CIDR address, typically with the CIDR address left blank. Its task would be to fill out that column. For simplicity, you might want to make one lookup function and 32 lookup tables in transforms.conf, each which sends the number of bits to the script, so that you only have to provide two columns.

A search command could do the same thing.

0 Karma

jeff
Contributor

accepting this lacking more elegant (ie, built-in) solution... may look at integrating with whois lookup- was looking at a couple of the apps on splunkbase.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...