贴代码

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);
	}

}

  

posted on 2015-03-10 16:39  zhangdong_ah  阅读(42124)  评论(0编辑  收藏  举报