Java中獲取本地IP地址

public InetAddress[] getLocalIPs()
{
InetAddress[] mArLocalIP = null;
if(mArLocalIP == null)
{
try
{
mArLocalIP = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
}
catch(Exception e)
{System.out.println("getHostIP error");}
}
return mArLocalIP;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章