java获取双网卡ip地址 - Go语言中文社区

java获取双网卡ip地址


package com.et59.License;

import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
/**
 * 
 * <p>Title: ListNets.java</p>
 * <p>Description: 获取双网卡ip</p>
 * <p>Copyright: 59et Software (c) 2011</p>
 * <p>Company: 点滴工作室</p>
 * @author Liuhh(jxausea@gmail.com)
 * @date 2014-7-18 下午03:52:03
 * @version 2.0
 *
 */
public class ListNets {
	public static void main(String args[]) throws SocketException {
		Enumeration<NetworkInterface> nets = NetworkInterface
				.getNetworkInterfaces();
		for (NetworkInterface netint : Collections.list(nets))
		if (null != netint.getHardwareAddress()) {
			List<InterfaceAddress> list = netint.getInterfaceAddresses();
			for (InterfaceAddress interfaceAddress : list) {
				String localip=interfaceAddress.getAddress().toString();
				System.out.println(localip);
			}
		}
		
	}
	


}



转载于:https://my.oschina.net/liuhaihua/blog/292508

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_33929309/article/details/92061142
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-01 21:04:00
  • 阅读 ( 1485 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢