Get port and actual server IP in Scala or Play Framework 2.x

This executes a shell command in Scala and returns the actual server IP instead of or the domain name of the host. #| is used to simulate piping of commands. Process and Seq are used for awk as $NF will lead to compilation errors otherwise.

The actual shell command is: ip route get | awk '{print $NF; exit}'

import scala.sys.process._

val addr = ("ip route get" #| Process(Seq("awk", "{print $NF; exit}"))).!!.trim
val port = System.getProperty("http.port", "9000")

[UPDATE 08 APR 2017]

A friend pointed out that the shell command could have been replaced by hostname --all-ip-addresses. This is preferred to hostname -i as the latter may return and is not recommended in the manual as it requires resolution of the hostname.