# Get first two octets of IP address

**URL:** <https://discuss.elastic.co/t/get-first-two-octets-of-ip-address/238361>\
**Category:** Logstash\
**Created:** [June 24, 2020, 2:32am UTC](https://discuss.elastic.co/t/get-first-two-octets-of-ip-address/238361 "2020-06-24T02:32:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leo\_Kwok](https://avatars.discourse-cdn.com/v4/letter/l/8baadc/32.png) [@Leo\_Kwok](https://discuss.elastic.co/u/Leo_Kwok)\
**Post date:** [June 24, 2020, 2:32am UTC](https://discuss.elastic.co/t/get-first-two-octets-of-ip-address/238361/1 "2020-06-24T02:32:24Z")

</div>

Hi,

I only need the first two octet of IP address, for example, only 91.255 for IP 91.225.201.1. Please advise how to get this in logstash filter.

Thanks,  
Leo

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [June 24, 2020, 2:15pm UTC](https://discuss.elastic.co/t/get-first-two-octets-of-ip-address/238361/2 "2020-06-24T14:15:20Z")

</div>

You could do it using dissect

```
dissect { mapping => { "someField" => "%{IP}.%{+IP}.%{}" } }
```

---

<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 22, 2020, 2:15pm UTC](https://discuss.elastic.co/t/get-first-two-octets-of-ip-address/238361/3 "2020-07-22T14:15:37Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
