Splunk Search

weird ip address with leading zeros

tuneit
New Member

Hi all,

I have a log file which has weird ip addresses as followings. There are leading zeros.

2014.06.10 13:14:56 src=011.009.120.010  dst=210.097.011.009 action=...
2014.06.10 13:14:57 src=010.123.090.003  dst=211.094.000.007 action=...
...

What would be the best way to eliminate the leading zeros?

Thank you.

Tags (1)
0 Karma
1 Solution

Ayn
Legend

Do you want to eliminate them in the actual indexed data or are you fine with removing the leading zeroes when you extract this to a field?

In the former case, you could use SEDCMD in props.conf:.

[yoursourcetype]
SEDCMD = s/(src=|dst=)0*([^.]+\.)0*([^.]+\.)0*([^.]+\.)0*(\d+)/\1\2\3\4\5/g

In the latter, using rex inline in your search will do what you want:

... | rex field=youripfield mode=sed "s/\.0+/./g"

View solution in original post

Ayn
Legend

Do you want to eliminate them in the actual indexed data or are you fine with removing the leading zeroes when you extract this to a field?

In the former case, you could use SEDCMD in props.conf:.

[yoursourcetype]
SEDCMD = s/(src=|dst=)0*([^.]+\.)0*([^.]+\.)0*([^.]+\.)0*(\d+)/\1\2\3\4\5/g

In the latter, using rex inline in your search will do what you want:

... | rex field=youripfield mode=sed "s/\.0+/./g"

tuneit
New Member

Thank you Ayn.

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...