Splunk Search

Lookup table with several IP ranges per row

pgomezji
Engager

Hi, I have a lookup table with IP ranges and locations. The problem is in the IP range column there can be several IP ranges separated by comma. How can match the client IP address with the right location?

Labels (1)
0 Karma
1 Solution

nickhills
Ultra Champion

To use a CIDR match you need each row in the lookup to have a single row per CIDR block.

So if your lookup has comma separated CIDR blocks you need to split these into rows.

You can either do this by manually splitting the data and adding rows, or you could use |inputlookup,  split the field, then mvexpand and re-write the (or create a new)  lookup.

 

 

| makeresults 
| eval cidr="192.168.1.0/24,192.168.30.0/24", location="London"
| table cidr location
| eval cidr=split(cidr,",")|mvexpand cidr

 

 

replace the first 3 lines with |inputlookup yourfile.csv
add at the end |outputlookup yourNewfile.csv to write a new file

| inputlookup yourfile.csv 
| eval cidr=split(cidr,",")|mvexpand cidr
| outputlookup yourNewfile.csv
If my comment helps, please give it a thumbs up!

View solution in original post

0 Karma

nickhills
Ultra Champion

To use a CIDR match you need each row in the lookup to have a single row per CIDR block.

So if your lookup has comma separated CIDR blocks you need to split these into rows.

You can either do this by manually splitting the data and adding rows, or you could use |inputlookup,  split the field, then mvexpand and re-write the (or create a new)  lookup.

 

 

| makeresults 
| eval cidr="192.168.1.0/24,192.168.30.0/24", location="London"
| table cidr location
| eval cidr=split(cidr,",")|mvexpand cidr

 

 

replace the first 3 lines with |inputlookup yourfile.csv
add at the end |outputlookup yourNewfile.csv to write a new file

| inputlookup yourfile.csv 
| eval cidr=split(cidr,",")|mvexpand cidr
| outputlookup yourNewfile.csv
If my comment helps, please give it a thumbs up!
0 Karma

pgomezji
Engager

Thanks, I was afraid of that answer.

0 Karma
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...