Splunk Search

Extracting unique IP addresses by Username

jginnetty
Explorer

Currently working on a IIS log file with standard fields. I’m looking to first determine the unique Usernames contained in the log and then list the unique IP addresses associated with each Username employed at login. “My Search String” determines the login event.

This gets me close:

index="main" " My Search String" | stats list(c_ip) by cs_username

This produces a list of the correct information except that the list of IP addresses is not unique and that is the problem I’m having trouble solving. Additionally it would be VERY helpful if there was a way to only display the rows if the number of unique IP addresses was greater than 1. The idea is to identify only the logins that have taken place from more than one IP address. I looked into the “WHERE” statement but it doesn’t seem to be designed for this.

Any help would be much appreciated.

Tags (1)
1 Solution

southeringtonp
Motivator

Instead of stats list, use stats values to get the distinct list:

index="main" " My Search String" | stats values(c_ip) by cs_username

To limit to cases where there is more than one distinct value:

index="main" " My Search String"
| stats dc(c_ip) as distinctCount values(c_ip) by cs_username
| where distinctCount>1

View solution in original post

southeringtonp
Motivator

Instead of stats list, use stats values to get the distinct list:

index="main" " My Search String" | stats values(c_ip) by cs_username

To limit to cases where there is more than one distinct value:

index="main" " My Search String"
| stats dc(c_ip) as distinctCount values(c_ip) by cs_username
| where distinctCount>1

jginnetty
Explorer

Very good, that certainly did the trick...

0 Karma

southeringtonp
Motivator

See inline edit above.

0 Karma

jginnetty
Explorer

Very good thanks! That solves problem number one. Is there any way to limit displaying the rows to circumstances where there are two or more IP addresses associated to one Username? This would make the difference between a list of about 10 events and 50 pages of information to page through.

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 ...