2017-10-04 32 views
0

我想使用scala在變量中設置ipaddress。我已經嘗試過下面的場景。我沒有得到我正在尋找的東西。如何在scala代碼中使用系統IP地址?

val sysip = System.InetAddress.getLocalHost(); 

你能幫忙嗎?

+0

的可能的複製找到更多的細節[獲取當前計算機使用Scala的公共IP地址](https://stackoverflow.com/questions/38392549/get-public- ip-address-of-the-current-machine-using-scala) –

+0

你試圖獲得哪個IP? – pedrofurla

回答

1
import java.net._ 

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

println(s"localIpAddress = $localIpAddress") 

您可以通過此link

+0

謝謝@fcat,它適用於我的用例。 – Nathon

相關問題