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")

View solution in original post

j_partsch
Explorer

Works Great! Thank you very much!

0 Karma
.conf21 Now Fully Virtual!
Register for FREE Today!

We've made .conf21 totally virtual and totally FREE! Our completely online experience will run from 10/19 through 10/20 with some additional events, too!