Splunk Search

Filtering events using a lookup table

waJesu
Path Finder

How do I use a lookup table to filter events based on a list of known malicious IP addresses (in CIDR format), or to exclude events from known internal IP ranges.

Labels (1)
Tags (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Have you looked up Create a CSV lookup definition?  You can define a field as match type CIDR.  The question is extremely vague.  If you want concrete help, illustrate mock data, desired results, and explain the logic between data and desired results.

Tags (1)

fredclown
Builder

You could do something like this. Imagine a lookup that looks like this.

ip_lookup.csv

ip
10.10.53.22
127.0.0.1
192.168.0.54

 

 

index=myindex ([| inputlookup ip_lookup.csv | stats values(eval("ip=\""+src_ip+"\"")) as search | eval search=mvjoin(search, " OR ")])

 

This produces ...

 

index=myindex (src_ip="10.10.53.22" OR src_ip="127.0.0.1" OR src_ip="192.168.0.54")

 

... or ...

 

index=myindex ([| inputlookup ip_lookup.csv | stats values(eval("src_ip!=\""+ip+"\"")) as search | eval search=mvjoin(search, " AND ")])

 

This produces ...

 

index=myindex (src_ip!="10.10.53.22" AND src_ip!="127.0.0.1" AND src_ip!="192.168.0.54")

 

 

You could even just put the sub-search into a macro that references the lookup to make using it easier for reuse. An example would be like this.

Macro name:
my_ip_macro

Macro definition:

 

[| inputlookup ip_lookup.csv
| stats values(eval("src_ip=\""+ip+"\"")) as search
| eval search=mvjoin(search, " OR ")]

 

 

Search using the macro:

 

index=myindex `my_ip_macro`

 

 

_JP
Contributor
0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

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

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...