貼代碼
GetIP.java
package com.datongsoft.wg.common.util;
import java.net.InetAddress;
public class GetIP {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
InetAddress addr = InetAddress.getLocalHost();
String ip=addr.getHostAddress().toString(); //獲取本機ip
String hostName=addr.getHostName().toString(); //獲取本機計算機名稱
System.out.println(ip);
System.out.println(hostName);
}
}
