Nathon
Nathon

Reputation: 165

How to get system IP address using in scala code?

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?

Upvotes: 6

Views: 5642

Answers (1)

fcat
fcat

Reputation: 1251

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

Upvotes: 10

Related Questions