Splunk Search

How to use regex determine whether a field is an IP address

xsstest
Communicator

I extracted a field named "apche_zhuji_sip", but the content is not accurate, some are not IP, how do I use regular expressions to filter non-IP contentalt text

Tags (1)
0 Karma
1 Solution

DalJeanis
Legend

It will be something like this

(your extract)
| regex apche_zhuji_sip="^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$" 

That's the basic, simple version that makes sure the IP has 1-3 numeric digits. You could also do a more complicated version that limits the nodes to 001-255...

| regex apche_zhuji_sip="(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"

View solution in original post

DalJeanis
Legend

It will be something like this

(your extract)
| regex apche_zhuji_sip="^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$" 

That's the basic, simple version that makes sure the IP has 1-3 numeric digits. You could also do a more complicated version that limits the nodes to 001-255...

| regex apche_zhuji_sip="(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
Get Updates on the Splunk Community!

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Your Voice Matters! Help Us Shape the New Splunk Lantern Experience

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Building Momentum: Splunk Developer Program at .conf25

At Splunk, developers are at the heart of innovation. That’s why this year at .conf25, we officially launched ...