欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

java中怎么獲取機(jī)器IP地址及MAC碼

這篇文章將為大家詳細(xì)講解有關(guān)java中怎么獲取機(jī)器IP地址及MAC碼,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

創(chuàng)新互聯(lián)公司擁有十載成都網(wǎng)站建設(shè)工作經(jīng)驗,為各大企業(yè)提供成都網(wǎng)站建設(shè)、網(wǎng)站制作服務(wù),對于網(wǎng)頁設(shè)計、PC網(wǎng)站建設(shè)(電腦版網(wǎng)站建設(shè))、成都app軟件開發(fā)公司、wap網(wǎng)站建設(shè)(手機(jī)版網(wǎng)站建設(shè))、程序開發(fā)、網(wǎng)站優(yōu)化(SEO優(yōu)化)、微網(wǎng)站、域名注冊等,憑借多年來在互聯(lián)網(wǎng)的打拼,我們在互聯(lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)積累了很多網(wǎng)站制作、網(wǎng)站設(shè)計、網(wǎng)絡(luò)營銷經(jīng)驗,集策劃、開發(fā)、設(shè)計、營銷、管理等網(wǎng)站化運(yùn)作于一體,具備承接各種規(guī)模類型的網(wǎng)站建設(shè)項目的能力。

java百分百獲取到機(jī)器IP地址及MAC碼

已測系統(tǒng):

windows linux unix

排除127.0.0.1 和 0.0.0.0.1等非正常IP

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
	
public class IpUtil {
	
	private IpUtil(){}
	/**
	 * 此方法描述的是:獲得服務(wù)器的IP地址
	 * @author:  zhangyang33@sinopharm.com
	 * @version: 2014年9月5日 下午4:57:15
	 */
	public static String getLocalIP() {
		String sIP = "";
		InetAddress ip = null;
		try {
			boolean bFindIP = false;
			Enumeration<NetworkInterface> netInterfaces = (Enumeration<NetworkInterface>) NetworkInterface
					.getNetworkInterfaces();
			while (netInterfaces.hasMoreElements()) {
				if (bFindIP) {
					break;
				}
				NetworkInterface ni = (NetworkInterface) netInterfaces
						.nextElement();
				
				Enumeration<InetAddress> ips = ni.getInetAddresses();
				while (ips.hasMoreElements()) {
					ip = (InetAddress) ips.nextElement();
					if (!ip.isLoopbackAddress() 
							&& ip.getHostAddress().matches(
									"(\\d{1,3}\\.){3}\\d{1,3}")) {
						bFindIP = true;
						break;
					}
				}
			}
		} catch (Exception e) {
			OutUtil.error(IpUtil.class, e.getMessage());
		}
		if (null != ip) {
			sIP = ip.getHostAddress();
		}
		return sIP;
	}
	
	/**
	 * 此方法描述的是:獲得服務(wù)器的IP地址(多網(wǎng)卡)
	 * @author:  zhangyang33@sinopharm.com
	 * @version: 2014年9月5日 下午4:57:15
	 */
	public static List<String> getLocalIPS() {
		InetAddress ip = null;
		List<String> ipList = new ArrayList<String>();
		try {
			Enumeration<NetworkInterface> netInterfaces = (Enumeration<NetworkInterface>) NetworkInterface
					.getNetworkInterfaces();
			while (netInterfaces.hasMoreElements()) {
				NetworkInterface ni = (NetworkInterface) netInterfaces
						.nextElement();
				Enumeration<InetAddress> ips = ni.getInetAddresses();
				while (ips.hasMoreElements()) {
					ip = (InetAddress) ips.nextElement();
					if (!ip.isLoopbackAddress() 
							&& ip.getHostAddress().matches(
									"(\\d{1,3}\\.){3}\\d{1,3}")) {
						ipList.add(ip.getHostAddress());
					}
				}
			}
		} catch (Exception e) {
			OutUtil.error(IpUtil.class, e.getMessage());
		}
		return ipList;
	}
	
	/**
	 * 此方法描述的是:獲得服務(wù)器的MAC地址
	 * @author:  zhangyang33@sinopharm.com
	 * @version: 2014年9月5日 下午1:27:25
	 */
	public static String getMacId() {
		String macId = "";
		InetAddress ip = null;
		NetworkInterface ni = null;
		try {
			boolean bFindIP = false;
			Enumeration<NetworkInterface> netInterfaces = (Enumeration<NetworkInterface>) NetworkInterface
					.getNetworkInterfaces();
			while (netInterfaces.hasMoreElements()) {
				if (bFindIP) {
					break;
				}
				ni = (NetworkInterface) netInterfaces
						.nextElement();
				// ----------特定情況,可以考慮用ni.getName判斷
				// 遍歷所有ip
				Enumeration<InetAddress> ips = ni.getInetAddresses();
				while (ips.hasMoreElements()) {
					ip = (InetAddress) ips.nextElement();
					if (!ip.isLoopbackAddress() // 非127.0.0.1
							&& ip.getHostAddress().matches(
									"(\\d{1,3}\\.){3}\\d{1,3}")) {
						bFindIP = true;
						break;
					}
				}
			}
		} catch (Exception e) {
			OutUtil.error(IpUtil.class, e.getMessage());
		}
		if (null != ip) {
			try {
				macId = getMacFromBytes(ni.getHardwareAddress());
			} catch (SocketException e) {
				OutUtil.error(IpUtil.class, e.getMessage());
			}
		}
		return macId;
	}
	
	/**
	 * 此方法描述的是:獲得服務(wù)器的MAC地址(多網(wǎng)卡)
	 * @author:  zhangyang33@sinopharm.com
	 * @version: 2014年9月5日 下午1:27:25
	 */
	public static List<String> getMacIds() {
		InetAddress ip = null;
		NetworkInterface ni = null;
		List<String> macList = new ArrayList<String>();
		try {
			Enumeration<NetworkInterface> netInterfaces = (Enumeration<NetworkInterface>) NetworkInterface
					.getNetworkInterfaces();
			while (netInterfaces.hasMoreElements()) {
				ni = (NetworkInterface) netInterfaces
						.nextElement();
				// ----------特定情況,可以考慮用ni.getName判斷
				// 遍歷所有ip
				Enumeration<InetAddress> ips = ni.getInetAddresses();
				while (ips.hasMoreElements()) {
					ip = (InetAddress) ips.nextElement();
					if (!ip.isLoopbackAddress() // 非127.0.0.1
							&& ip.getHostAddress().matches(
									"(\\d{1,3}\\.){3}\\d{1,3}")) {
						macList.add(getMacFromBytes(ni.getHardwareAddress()));
					}
				}
			}
		} catch (Exception e) {
			OutUtil.error(IpUtil.class, e.getMessage());
		}
		return macList;
	}
	
	private static String getMacFromBytes(byte[] bytes) {
		StringBuffer mac = new StringBuffer();
		byte currentByte;
		boolean first = false;
		for (byte b : bytes) {
			if (first) {
				mac.append("-");
			}
			currentByte = (byte) ((b & 240) >> 4);
			mac.append(Integer.toHexString(currentByte));
			currentByte = (byte) (b & 15);
			mac.append(Integer.toHexString(currentByte));
			first = true;
		}
		return mac.toString().toUpperCase();
	}
	
}

關(guān)于java中怎么獲取機(jī)器IP地址及MAC碼就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

分享文章:java中怎么獲取機(jī)器IP地址及MAC碼
本文鏈接:http://aaarwkj.com/article30/jjjdpo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航網(wǎng)站設(shè)計、軟件開發(fā)關(guān)鍵詞優(yōu)化、品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管
九九九视频精品免费九九| 国产一区二区三区本色| 日本的黄色录像一级带| av黄色天堂在线观看| 国产男女猛进猛出精品91| 久久se精品人妻一区二区三区| 亚洲国产日韩欧美视频| 97免费观看在线观看| 91亚洲蜜桃内射后入在线观看| 亚洲第一毛片免费在线观看| 在线亚洲精品一区二区| 天堂中文字幕在线乱码一区 | 日韩欧美亚洲天堂视频| 亚洲国产在线一区二区| 欧美熟妇精品一区二区蜜桃| 国产成人av网站在线观看| 91麻豆精品国产综合久久久| 亚洲av第一区综合激情久久久| 国产av手机自拍看片| 精品一区二区在线欧美日韩| 夜夜高潮夜夜爽免费观看| 国产欧美日韩精品av| 日本精品视频免费网| 国产激情久久久久久久久久久| 91九色蝌蚪国产欧美亚洲| 亚洲欧美激情国产综合久久| 开心五月婷婷丁香综合| 亚洲av最近在线观看| 三级av电影中文字幕| 丁香婷婷激情五月天综合| 尹人大香蕉在线视频| 男人午夜福利视频在线观看| 日韩一区二区三区av| 欧美一区二区三区午夜| 91欧美日韩国产在线观看| 97国产精品视频在线观看| 亚洲欧美综合区丁香六月| 久久人妻一区二区三区免费密臀| 欧美国产日韩激情在线| 日韩在线国产精品一区| 亚洲乱码一区二区av|