当前位置: 首页>>代码示例>>Java>>正文


Java NetworkInterface.isVirtual方法代码示例

本文整理汇总了Java中java.net.NetworkInterface.isVirtual方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkInterface.isVirtual方法的具体用法?Java NetworkInterface.isVirtual怎么用?Java NetworkInterface.isVirtual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.NetworkInterface的用法示例。


在下文中一共展示了NetworkInterface.isVirtual方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: formatFlags

import java.net.NetworkInterface; //导入方法依赖的package包/类
/** format network interface flags */
private static String formatFlags(NetworkInterface nic) throws SocketException {
    StringBuilder flags = new StringBuilder();
    if (nic.isUp()) {
        flags.append("UP ");
    }
    if (nic.supportsMulticast()) {
        flags.append("MULTICAST ");
    }
    if (nic.isLoopback()) {
        flags.append("LOOPBACK ");
    }
    if (nic.isPointToPoint()) {
        flags.append("POINTOPOINT ");
    }
    if (nic.isVirtual()) {
        flags.append("VIRTUAL ");
    }
    flags.append("mtu:" + nic.getMTU());
    flags.append(" index:" + nic.getIndex());
    return flags.toString();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:IfConfig.java

示例2: getIp

import java.net.NetworkInterface; //导入方法依赖的package包/类
public String getIp() {
    String id = "-1";
    try {
        Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
        InetAddress ip = null;
        while (allNetInterfaces.hasMoreElements()) {
            NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
            if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
                continue;
            } else {
                Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
                while (addresses.hasMoreElements()) {
                    ip = addresses.nextElement();
                    if (ip != null && ip instanceof Inet4Address) {
                        id = ip.getHostAddress();
                    }
                }
            }
        }
    } catch (Exception e) {
        logger.error("Cannot get Id, something wrong with getting Ipv4 address");
    }
    return id;
}
 
开发者ID:xiongbeer,项目名称:Cobweb,代码行数:25,代码来源:IdProvider.java

示例3: getLocalAddress

import java.net.NetworkInterface; //导入方法依赖的package包/类
/**
 * 获取本机的IP
 * 
 * @return Ip地址
 */
private static String getLocalAddress() {
       try {
           for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements();) {
               NetworkInterface networkInterface = interfaces.nextElement();
               if (networkInterface.isLoopback() || networkInterface.isVirtual() || !networkInterface.isUp()) {
                   continue;
               }
               Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
               if (addresses.hasMoreElements()) {
               	InetAddress address = addresses.nextElement();
               	if(address instanceof Inet4Address) {
               		return address.getHostAddress();
               	}
               }
           }
       } catch (SocketException e) {
           logger.debug("Error when getting host ip address: <{}>.", e.getMessage());
       }
       return "127.0.0.1";
   }
 
开发者ID:xtuhcy,项目名称:socks5-netty,代码行数:26,代码来源:ProxyFlowLog4j.java

示例4: getIpAddress

import java.net.NetworkInterface; //导入方法依赖的package包/类
private static InetAddress getIpAddress(AddressSelectionCondition condition) throws
    SocketException {
  // Before we connect somewhere, we cannot be sure about what we'd be bound to; however,
  // we only connect when the message where client ID is, is long constructed. Thus,
  // just use whichever IP address we can find.
  Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
  while (interfaces.hasMoreElements()) {
    NetworkInterface current = interfaces.nextElement();
    if (!current.isUp() || current.isLoopback() || current.isVirtual()) continue;
    Enumeration<InetAddress> addresses = current.getInetAddresses();
    while (addresses.hasMoreElements()) {
      InetAddress addr = addresses.nextElement();
      if (addr.isLoopbackAddress()) continue;
      if (condition.isAcceptableAddress(addr)) {
        return addr;
      }
    }
  }

  throw new SocketException("Can't get our ip address, interfaces are: " + interfaces);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:22,代码来源:Addressing.java

示例5: doGetIpv4AddressFromNetworkInterface

import java.net.NetworkInterface; //导入方法依赖的package包/类
/**
 * docker环境中,有时无法通过InetAddress.getLocalHost()获取 ,会报unknown host Exception, system error
 * 此时,通过遍历网卡接口的方式规避,出来的数据不一定对
 */
private static void doGetIpv4AddressFromNetworkInterface() throws SocketException {
  Enumeration<NetworkInterface> iterNetwork = NetworkInterface.getNetworkInterfaces();

  while (iterNetwork.hasMoreElements()) {
    NetworkInterface network = iterNetwork.nextElement();

    if (!network.isUp() || network.isLoopback() || network.isVirtual()) {
      continue;
    }

    Enumeration<InetAddress> iterAddress = network.getInetAddresses();
    while (iterAddress.hasMoreElements()) {
      InetAddress address = iterAddress.nextElement();

      if (address.isAnyLocalAddress() || address.isLoopbackAddress() || address.isMulticastAddress()
          || Inet6Address.class.isInstance(address)) {
        continue;
      }

      if (Inet4Address.class.isInstance(address)) {
        LOGGER.info(
            "add network interface name:" + network.getName() + ",host address:" + address.getHostAddress());
        allInterfaceAddresses.put(network.getName(), address);
      }
    }
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:32,代码来源:NetUtils.java

示例6: getLocalNetWorkIp

import java.net.NetworkInterface; //导入方法依赖的package包/类
/**
 * 获取本机的网络IP
 */
public static String getLocalNetWorkIp() {
	if (localIp != null) {
		return localIp;
	}
	try {
		Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
		InetAddress ip = null;
		while (netInterfaces.hasMoreElements()) {// 遍历所有的网卡
			NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
			if (ni.isLoopback() || ni.isVirtual()) {// 如果是回环和虚拟网络地址的话继续
				continue;
			}
			Enumeration<InetAddress> addresss = ni.getInetAddresses();
			while (addresss.hasMoreElements()) {
				InetAddress address = addresss.nextElement();
				if (address instanceof Inet4Address) {// 这里暂时只获取ipv4地址
					ip = address;
					break;
				}
			}
			if (ip != null) {
				break;
			}
		}
		if (ip != null) {
			localIp = ip.getHostAddress();
		} else {
			localIp = "127.0.0.1";
		}
	} catch (Exception e) {
		localIp = "127.0.0.1";
	}
	return localIp;
}
 
开发者ID:funtl,项目名称:framework,代码行数:38,代码来源:AlipayUtils.java

示例7: getInetAddresses

import java.net.NetworkInterface; //导入方法依赖的package包/类
public static final ArrayList<InetAddress> getInetAddresses(InetAddressFilter inetAddressFilter) {
    try {
        final ArrayList<InetAddress> inetAddresses = new ArrayList<>();
        final Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            final NetworkInterface networkInterface = networkInterfaces.nextElement();
            if (networkInterface == null || networkInterface.isLoopback() || !networkInterface.isUp() || networkInterface.isVirtual() || networkInterface.isPointToPoint()) {
                continue;
            }
            final Enumeration<InetAddress> addresses = networkInterface.getInetAddresses();
            while (addresses.hasMoreElements()) {
                final InetAddress inetAddress = addresses.nextElement();
                if (inetAddress == null) {
                    continue;
                }
                if (inetAddressFilter.filter(inetAddress)) {
                    inetAddresses.add(inetAddress);
                }
            }
        }
        return inetAddresses;
    } catch (Exception ex) {
        System.err.println("NetworkUtil: getInetAddresses error");
        ex.printStackTrace();
        return new ArrayList<>();
    }
}
 
开发者ID:Panzer1119,项目名称:Supreme-Bot,代码行数:28,代码来源:NetworkUtil.java

示例8: getInetAddresses

import java.net.NetworkInterface; //导入方法依赖的package包/类
/**
 * @return a bunch of InetAddresses that are "real", ie, not virtual,
 *         loopback, multicast and are up.
 */
public static List<Pair<NetworkInterface, InetAddress>> getInetAddresses()
{
	List<Pair<NetworkInterface, InetAddress>> addrs = Lists.newArrayList();
	try
	{
		Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
		while( nis.hasMoreElements() )
		{
			NetworkInterface ni = nis.nextElement();
			if( !ni.isLoopback() && !ni.isVirtual() && ni.isUp() )
			{
				for( Enumeration<InetAddress> ias = ni.getInetAddresses(); ias.hasMoreElements(); )
				{
					InetAddress ia = ias.nextElement();
					if( !ia.isMulticastAddress() && !ia.isLoopbackAddress() )
					{
						addrs.add(new Pair<NetworkInterface, InetAddress>(ni, ia));
					}
				}
			}
		}
	}
	catch( SocketException e )
	{
		// Carry on
	}
	return addrs;
}
 
开发者ID:equella,项目名称:Equella,代码行数:33,代码来源:NetworkUtils.java

示例9: getLocalInetAddresses

import java.net.NetworkInterface; //导入方法依赖的package包/类
public static List<InetAddress> getLocalInetAddresses() throws IOException {
    List<InetAddress> ret = new ArrayList<>();

    Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
    if (networkInterfaces == null) {
        return ret;
    }

    while (networkInterfaces.hasMoreElements()) {
        NetworkInterface card = networkInterfaces.nextElement();

        if (card.isLoopback() || card.isPointToPoint() || card.isVirtual() || !card.isUp()) {
            continue;
        }

        Enumeration<InetAddress> addresses = card.getInetAddresses();
        while (addresses.hasMoreElements()) {
            InetAddress inetAddress = addresses.nextElement();
            int index = ret.size();

            if (Inet4Address.class.isInstance(inetAddress)) {
                ret.add(index, inetAddress);
            }
        }
    }

    return ret;
}
 
开发者ID:dainesch,项目名称:HueSense,代码行数:29,代码来源:NetworkUtil.java

示例10: getLocalNetWorkIp

import java.net.NetworkInterface; //导入方法依赖的package包/类
/**
 * 获取本机的网络IP
 */
public static String getLocalNetWorkIp() {
    if (localIp != null) {
        return localIp;
    }
    try {
        Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
        InetAddress ip = null;
        while (netInterfaces.hasMoreElements()) {// 遍历所有的网卡
            NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
            if (ni.isLoopback() || ni.isVirtual()) {// 如果是回环和虚拟网络地址的话继续
                continue;
            }
            Enumeration<InetAddress> addresss = ni.getInetAddresses();
            while (addresss.hasMoreElements()) {
                InetAddress address = addresss.nextElement();
                if (address instanceof Inet4Address) {// 这里暂时只获取ipv4地址
                    ip = address;
                    break;
                }
            }
            if (ip != null) {
                break;
            }
        }
        if (ip != null) {
            localIp = ip.getHostAddress();
        } else {
            localIp = "127.0.0.1";
        }
    } catch (Exception e) {
        localIp = "127.0.0.1";
    }
    return localIp;
}
 
开发者ID:wendal,项目名称:alipay-sdk,代码行数:38,代码来源:AlipayUtils.java

示例11: getLocalNetWorkIp

import java.net.NetworkInterface; //导入方法依赖的package包/类
public static String getLocalNetWorkIp() {
    if (localIp != null) {
        return localIp;
    }
    try {
        Enumeration<NetworkInterface> netInterfaces = NetworkInterface.getNetworkInterfaces();
        InetAddress ip = null;
        while (netInterfaces.hasMoreElements()) {// 遍历所有的网卡
            NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
            if (ni.isLoopback() || ni.isVirtual()) {// 如果是回环和虚拟网络地址的话继续
                continue;
            }
            Enumeration<InetAddress> addresss = ni.getInetAddresses();
            while (addresss.hasMoreElements()) {
                InetAddress address = addresss.nextElement();
                if (address instanceof Inet4Address) {// 这里暂时只获取ipv4地址
                    ip = address;
                    break;
                }
            }
            if (ip != null) {
                break;
            }
        }
        if (ip != null) {
            localIp = ip.getHostAddress();
        } else {
            localIp = "127.0.0.1";
        }
    } catch (Exception e) {
        localIp = "127.0.0.1";
    }
    return localIp;
}
 
开发者ID:1991wangliang,项目名称:pay,代码行数:35,代码来源:AlipayUtils.java

示例12: readInfo

import java.net.NetworkInterface; //导入方法依赖的package包/类
private List<InetAddress> readInfo(String name) {

        List<InetAddress> ipList = new ArrayList<InetAddress>();

        InetAddress ip = null;
        Enumeration<NetworkInterface> netInterfaces;
        try {
            netInterfaces = NetworkInterface.getNetworkInterfaces();

            while (netInterfaces.hasMoreElements()) {

                NetworkInterface ni = netInterfaces.nextElement();

                Enumeration<InetAddress> ips = ni.getInetAddresses();
                while (ips.hasMoreElements()) {
                    ip = ips.nextElement();

                    if (!ni.isVirtual() && !ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1) {

                        if (name != null) {

                            if (ni.getName().equalsIgnoreCase(name)) {
                                ipList.add(ip);
                            }
                        }
                        else {

                            ipList.add(ip);
                        }

                    }
                }

            }
        }
        catch (SocketException e) {
            // ignore
        }

        return ipList;
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:42,代码来源:HostNewworkInfo.java


注:本文中的java.net.NetworkInterface.isVirtual方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。