# Convert mapped IPv6 to IPv4

**URL:** https://discuss.elastic.co/t/convert-mapped-ipv6-to-ipv4/158651
**Category:** Logstash
**Created:** [November 28, 2018, 9:07pm UTC](https://discuss.elastic.co/t/convert-mapped-ipv6-to-ipv4/158651 "2018-11-28T21:07:22Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![nandrik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nandrik/32/39951_2.png) [@nandrik](https://discuss.elastic.co/u/nandrik)
#### Post date: [November 28, 2018, 9:28pm UTC](https://discuss.elastic.co/t/convert-mapped-ipv6-to-ipv4/158651/2 "2018-11-28T21:28:49Z")

</div>

Combining the [referenced ruby filter code](https://discuss.elastic.co/t/converting-a-numeric-ipv4-address-to-dotted-format-string/121193) with [Ruby conversion code](https://stackoverflow.com/questions/38984972/ruby-how-to-convert-ipv6-uo-address-to-ipv4-ip-address), I'm trying out the following piece of code in my filter:

```auto
if(![srcIPv4] and [srcIPv6]) {	
			mutate { add_field => { "srcIPv4" => ""}}
			ruby {
    			init => 'require "ipaddr"'
  			    code => '
  			        	ipv6 = IPAddr.new(event.get("srcIPv6"))
  				        event.set("srcIPv4",ipv6.native)'
			}
		}

```

I've used a workaround using `[geoip][ip]` but I think I'm paying a high computational price for IPv6-to-IPv4 conversion.

The error that I'm getting in logstash's logs, because of this, is:

```auto
[2018-12-01T17:34:13,309][ERROR][logstash.filters.ruby] Ruby exception occurred: Missing Converter handling for full class name=org.jruby.RubyObjectVar2, simple name=RubyObjectVar2

```

And [a link with the Ruby code working in the tester](https://repl.it/repls/RegularInsubstantialDisks).

Any help appreciated, thanks!

---

_[View the full topic](https://discuss.elastic.co/t/convert-mapped-ipv6-to-ipv4/158651)._
