scala - How do I obtain the client's IPv6 address in the Akka/Spray framework? -


i using below code ipv4 address:

import spray.http.remoteaddress ... val ipv4: string = remoteaddress.tooption.map(_.gethostaddress).getorelse("<unknown>") 

however, cannot seem find information on doing same thing ipv6. assistance on appreciated.

it not depend method - depends configuration of network.

look @ source code of spray.http.remoteaddress:

def apply(bytes: array[byte]): remoteaddress = {     require(bytes.length == 4 || bytes.length == 16)     try ip(inetaddress.getbyaddress(bytes)) catch { case _: unknownhostexception ⇒ unknown } } 

this code wraps both ipv4 (4 byte) , ipv6 (16 byte). result receive ipv4 address, ipv6 address or special pv4-mapped-to-ipv6 address depends network settings.

try run code on local pc network interface configured use ipv6 , see.

this object receive java: http://docs.oracle.com/javase/8/docs/api/java/net/inetaddress.html


Comments