Splunk Search

How to rex the root domain and parse the .TLD from email sender logs?

packet_hunter
Contributor

Scenario: I am trying to list all incoming sender domains and tlds. For example, sender@blah.domain.tld, looking for just "domain" and "tld". For some reason I am not finding the right syntax. I am also not interested in senders from my domain.

enter code
index=mail sourcetype=xemail sender != *@mydomain* | search sender =* | rex field = sender ".*@(?< domain >.*)" | stats list(domain)
here

In addition to the needed rex syntax, please let me know if there is a more efficient way to achieve this.

Thank you

Tags (2)
0 Karma
1 Solution

somesoni2
Revered Legend

Try something like this

Updated
removed a bracket

index=mail sourcetype=xemail sender != @mydomain | search sender= | rex field=sender "[@\.](?<domain>\w+\.\w+)$" | stats list(domain)

To get tld as separate field

  index=mail sourcetype=xemail sender != @mydomain | search sender= | rex field=sender "[@\.](?<domain>\w+)\.(?<tld>\w+)$" | stats list(domain)

View solution in original post

0 Karma

javiergn
Super Champion

What about this (not tested)

| rex field=sender "@(?<domain>[^\.]+).*?(?<tld>[^\.]+)$"
0 Karma

packet_hunter
Contributor

not working

0 Karma

javiergn
Super Champion

Just forced the wildcard to be non-greedy. Try now:

| rex field=sender "@(?<domain>[^\.]+).*?(?<tld>[^\.]+)$"
0 Karma

packet_hunter
Contributor

This works now too. Thanks

0 Karma

somesoni2
Revered Legend

Try something like this

Updated
removed a bracket

index=mail sourcetype=xemail sender != @mydomain | search sender= | rex field=sender "[@\.](?<domain>\w+\.\w+)$" | stats list(domain)

To get tld as separate field

  index=mail sourcetype=xemail sender != @mydomain | search sender= | rex field=sender "[@\.](?<domain>\w+)\.(?<tld>\w+)$" | stats list(domain)
0 Karma

packet_hunter
Contributor
| search sender= * | rex field=sender "[@\.]((?<domain>\w+)\.\w+)$" | stats list(domain)

this works for just the root domains, but do you have an example with .tlds in a separate column as well?

Thank you!

0 Karma
Get Updates on the Splunk Community!

Detecting Brute Force Account Takeover Fraud with Splunk

This article is the second in a three-part series exploring advanced fraud detection techniques using Splunk. ...

Buttercup Games: Further Dashboarding Techniques (Part 9)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...

Buttercup Games: Further Dashboarding Techniques (Part 8)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...