# How do we match multiple random ips?

**URL:** <https://discuss.elastic.co/t/how-do-we-match-multiple-random-ips/1507>\
**Category:** Logstash\
**Created:** [May 28, 2015, 6:10pm UTC](https://discuss.elastic.co/t/how-do-we-match-multiple-random-ips/1507 "2015-05-28T18:10:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://discuss.elastic.co/u/Ben)\
**Post date:** [May 28, 2015, 6:10pm UTC](https://discuss.elastic.co/t/how-do-we-match-multiple-random-ips/1507/1 "2015-05-28T18:10:56Z")

</div>

I am trying to match random number of ips in my access logs. Basically, the access logs looks like this

10.xx.xx.xx 107.xx.xxx.xxx 107.xx.xx.xx, 184.xx.xx.xx, 131.xx.xx.xx, 74.xx.xx.xxx, 209.xx.xx.xxx, 10.xx.xx.x, 10.xx.xx.x.x [27/May/2015:23:59:59 -0400]

The number of ips are random - basically sometimes it is 4, sometimes 6, sometimes 8 and sometime 10. And they also do not follow any coherent pattern like starting with certain ips(10.84..) and ending with certain ips (208....).The only pattern I can see is that it does have %{SYSLOG5424SD} after the ips.

What I want to do is to be able to get all these ips as a filter. Is there a way to match all these together ? When i use grok debugger it gives me %{IP} %{IP} %{IP} .... But that doesn't help me as the number of %{IP} could be different for each log lines. I want to create a pattern that says, he match all the ips that you see in this log line and label them as IPs. What is the best way to do this ?

Any pointers would be of great help.  
Thanks,  
Ben

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [May 28, 2015, 6:33pm UTC](https://discuss.elastic.co/t/how-do-we-match-multiple-random-ips/1507/2 "2015-05-28T18:33:45Z")

</div>

If you're okay with getting all IPs in an array field you can just use [grok](https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html) extract all the IPs to a string and use the [mutate filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html) to split that string.

```
filter {
  grok {
    match => ["message", "^(?<ip>%{IP}(, %{IP})*) ..."]
  }
  mutate {
    split => ["ip", ", "]
  }
}

```

It looks like you might always have at least two IPs, each followed by a space, followed by a comma-separated list of IPs. In that you'll have to adjust the filters a bit but it shouldn't be too hard.

---

<div class="post-metadata">

**Author:** ![Ben](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@Ben](https://discuss.elastic.co/u/Ben)\
**Post date:** [May 28, 2015, 9:22pm UTC](https://discuss.elastic.co/t/how-do-we-match-multiple-random-ips/1507/3 "2015-05-28T21:22:45Z")

</div>

This helps!

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 5:39am UTC](https://discuss.elastic.co/t/how-do-we-match-multiple-random-ips/1507/4 "2017-07-06T05:39:08Z")

</div>


