Splunk Search

Search 1hr using IPs from 24hr

mztopp
Explorer

How would I take a 24 hour search such as: index=* | iplocation src_ip | stats count by src_ip, Country, dest_ip, dest_port | sort 10 -count     that can effectively use the IPs from a 24 hour search, to search for the traffic in the last hour (using the same 10 IPs from the 24hr not the most popular from the last hour)? I have tried to bucket _time span=1hr, but that just searches through for the most active ips in the last hour and changes what I need. Any suggestions are appreciated!

Labels (3)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Something like this - use eventstats to find the most popular src_ip Country dest_ip etc (whatever criteria you want); sort descending by count and criteria just in case more than one combination has the same count; establish a combined key for the combination,; use streamstats based on this key to determine a rank; filter based on established rank; filter based on time criteria; calculate counts for surviving events

index=* 
| iplocation src_ip 
| eventstats count by src_ip, Country, dest_ip, dest_port 
| sort -count src_ip Country dest_ip dest_port
| eval key=src_ip.":".Country.":".dest_ip.":".dest_port
| streamstats dc(key) as rank
| where rank <= 10
| fields - rank key count
| where _time > relative_time(now(),"-1h@m")
| stats count by src_ip, Country, dest_ip, dest_port
0 Karma

manjunathmeti
Champion

hi @mztopp,

If field src_ip is part of the index then you can try this:

index=index earliest=-1h [search index=index earliest=-24h | top limit=10 src_ip | fields src_ip | format] | iplocation src_ip | stats count by src_ip, Country, dest_ip, dest_port

 

If this reply helps you, an upvote/like would be appreciated.

0 Karma

mztopp
Explorer

Just to be clear, my hope is to use this data for a report, so ideally I would be able to accomplish this all in one single search.

0 Karma

mztopp
Explorer

I ended up using a separate lookup to store the IPs. Not really ideal, but I wasn't getting the results I was looking for. Thanks for the help!

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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...