Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get system IP address using in scala code?

Tags:

scala

I want to set the ipaddress in variable using scala. I have tried below scenario. I did not get exactly what I was looking for.

val sysip = System.InetAddress.getLocalHost();

Can you please help?

like image 252
Nathon Avatar asked Oct 04 '17 20:10

Nathon


1 Answers

import java.net._

val localhost: InetAddress = InetAddress.getLocalHost
val localIpAddress: String = localhost.getHostAddress

println(s"localIpAddress = $localIpAddress")

You can find more details via this link

like image 120
fcat Avatar answered Sep 28 '22 07:09

fcat