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!

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...

September Community Champions: A Shoutout to Our Contributors!

As we close the books on another fantastic month, we want to take a moment to celebrate the people who are the ...

Splunk Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...