Splunk Search

How do I translate standard IPv4 addresses into a format with leading zeroes in each octet in order for each octet to always contain 3 digits?

j_partsch
Explorer

I need to do this to perform lookups on a customer database where the IP addresses are stored in the format with leading zeroes.

Thank you!

1 Solution

somesoni2
Revered Legend

Try like this (run anywhere sample, replace first line with your actual search and update the field name). Two methods give, use any one.

| gentimes start=-1 | eval ip_addr="111.22.3.44 1.22.33.444 11.22.33.44" | table ip_addr | makemv ip_addr | mvexpand ip_addr 
| eval ip_addr_modified=replace(replace(ip_addr,"(\d+)\.(\d+)\.(\d+)\.(\d+)","00\1.00\2.00\3.00\4"),"0*(\d{3})\.0*(\d{3})\.0*(\d{3})\.0*(\d{3})","\1.\2.\3.\4")
| eval ip_addr_modified2=replace("00".replace(ip_addr,"\.",".00"),"0*(\d{3})\.0*(\d{3})\.0*(\d{3})\.0*(\d{3})","\1.\2.\3.\4")

View solution in original post

somesoni2
Revered Legend

Try like this (run anywhere sample, replace first line with your actual search and update the field name). Two methods give, use any one.

| gentimes start=-1 | eval ip_addr="111.22.3.44 1.22.33.444 11.22.33.44" | table ip_addr | makemv ip_addr | mvexpand ip_addr 
| eval ip_addr_modified=replace(replace(ip_addr,"(\d+)\.(\d+)\.(\d+)\.(\d+)","00\1.00\2.00\3.00\4"),"0*(\d{3})\.0*(\d{3})\.0*(\d{3})\.0*(\d{3})","\1.\2.\3.\4")
| eval ip_addr_modified2=replace("00".replace(ip_addr,"\.",".00"),"0*(\d{3})\.0*(\d{3})\.0*(\d{3})\.0*(\d{3})","\1.\2.\3.\4")

j_partsch
Explorer

Works Great! Thank you very much!

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...