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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...