`
lushuaiyin
  • 浏览: 670963 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

获取IP地址的一个工具类

 
阅读更多

package org.hd.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IPUtil {
	// 取得本机IP地址
	public static String getLocalIP() {
		InetAddress LocalIP =null;
		try {
			LocalIP = InetAddress.getLocalHost();
		} catch (UnknownHostException e) {
            e.printStackTrace();
		}
		return LocalIP.getHostAddress();
	}

	// 取得服务器网络地址
	public static String getServerIP(String www) {
		InetAddress ServerIP =null;
		try {
			ServerIP = InetAddress.getByName(www.trim());
			// 取得例如www.baidu.com的IP地址
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		return ServerIP.getHostAddress();
	}
	
	public static void getAllIP(){
		
	}
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics