Feedback
Got feedback? We want it! Submit your comments and suggestions for our community here.

cidrmatch with lookup and field as arguments

PeterPurker
Engager

Hello Hello!

I'm trying to match the values from a lookup file, in this case being Amazon CIDRS values against ip-adresses that are dynamically retrieved from events, but I can't get it to work, the following is a snippet of what I have.

 

 

| append [| inputlookup cidr_aws.csv ]
| foreach CIDR [ eval matched_ip = if(cidrmatch(<<FIELD>>, ip_address), ip_address, null()) ]
| search matched_ip!=null
| table matched_ip, CIDR

 

 

 There is nothing outputted from this, and if I remove the "| search matched_ip!=null" then I can see that the IP appears which means that it failed the "cidrmatch" comparison and after some experimenting I figured out that the entire thing works If I hardcode either the "<<FIELD>>" value or "ip_address" like the following two examples..

 

 

| append [| inputlookup cidr_aws.csv ]
| foreach CIDR [ eval matched_ip = if(cidrmatch("3.248.0.0/13", ip_address), ip_address, null()) ]
| search matched_ip!=null
| table matched_ip, CIDR, Country

 

 or

 

| append [| inputlookup cidr_aws.csv ]
| foreach CIDR [ eval matched_ip = if(cidrmatch(<<FIELD>>, "3.248.163.69"), ip_address, null()) ]
| search matched_ip!=null
| table matched_ip, CIDR, Country

 

but this is not optimal since it's supposed to be dynamic.

 

Does anybody know how to solve this?

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The <<FIELD>> keyword is a text substitution and you still need quotes so try this

| append [| inputlookup cidr_aws.csv ]
| foreach CIDR [ eval matched_ip = if(cidrmatch("<<FIELD>>", ip_address), ip_address, null()) ]
| search matched_ip!=null
| table matched_ip, CIDR

 

---
If this reply helps you, Karma would be appreciated.
0 Karma

PeterPurker
Engager

Hello, I tried what you suggested and it doesn't work, it just behaves like it did previously.

If I rewrite the code to the following in order to see what is being printed out from the file

 

      | append [| inputlookup cidr_aws.csv ]
      | foreach CIDR [ eval value="<<FIELD>>" ]
      | table value

 

 then the column name is being printed

PeterPurker_0-1737108114806.png

if I instead remove the "" around <<FIELD>>, like the following

 

      | append [| inputlookup cidr_aws.csv ]
      | foreach CIDR [ eval value=<<FIELD>> ]
      | table value

 


then it actually prints out the correct values from the file but it includes a random blank line which isn't in the file

PeterPurker_1-1737108156363.png

 

Do you have any other idea on what else that I could try?

 

richgalloway
SplunkTrust
SplunkTrust

I have no other ideas.  Sorry.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...