當前位置: 首頁>>代碼示例>>Java>>正文


Java InterfaceAddress類代碼示例

本文整理匯總了Java中java.net.InterfaceAddress的典型用法代碼示例。如果您正苦於以下問題:Java InterfaceAddress類的具體用法?Java InterfaceAddress怎麽用?Java InterfaceAddress使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


InterfaceAddress類屬於java.net包,在下文中一共展示了InterfaceAddress類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateIpAddress

import java.net.InterfaceAddress; //導入依賴的package包/類
private void updateIpAddress() {
    try {
        Enumeration<NetworkInterface> b = NetworkInterface.getNetworkInterfaces();
        ipAddress = null;
        while( b.hasMoreElements()){
            NetworkInterface iface = b.nextElement();
            if (iface.getName().startsWith("dock")) {
                continue;
            }
            for ( InterfaceAddress f : iface.getInterfaceAddresses()) {
                if (f.getAddress().isSiteLocalAddress()) {
                    ipAddress = f.getAddress().getHostAddress();
                }
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }
}
 
開發者ID:Sixt,項目名稱:ja-micro,代碼行數:20,代碼來源:RegistrationManager.java

示例2: main

import java.net.InterfaceAddress; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();

    while (nics.hasMoreElements()) {
        NetworkInterface nic = nics.nextElement();
        for (InterfaceAddress iaddr : nic.getInterfaceAddresses()) {
            boolean valid = checkPrefix(iaddr);
            if (!valid) {
                passed = false;
                debug(nic.getName(), iaddr);
            }
            InetAddress ia = iaddr.getAddress();
            if (ia.isLoopbackAddress() && ia instanceof Inet4Address) {
                // assumption: prefix length will always be 8
                if (iaddr.getNetworkPrefixLength() != 8) {
                    out.println("Expected prefix of 8, got " + iaddr);
                    passed = false;
                }
            }
        }
    }

    if (!passed)
        throw new RuntimeException("Failed: some interfaces have invalid prefix lengths");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:NetworkPrefixLength.java

示例3: getBroadcastAddress

import java.net.InterfaceAddress; //導入依賴的package包/類
static List<String> getBroadcastAddress() throws BrowsingException, SocketException {
  Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();

  List<String> broadcastAddresses = new ArrayList<>();

  while (interfaces.hasMoreElements()) {
    NetworkInterface networkInterface = interfaces.nextElement();
    if (networkInterface.isLoopback()) {
      continue;
    }

    for (InterfaceAddress interfaceAddress :
            networkInterface.getInterfaceAddresses()) {
      InetAddress broadcast = interfaceAddress.getBroadcast();

      if (broadcast != null) {
        broadcastAddresses.add(broadcast.toString().substring(1));
      }
    }
  }

  return broadcastAddresses;
}
 
開發者ID:google,項目名稱:samba-documents-provider,代碼行數:24,代碼來源:BroadcastUtils.java

示例4: getBroadcast

import java.net.InterfaceAddress; //導入依賴的package包/類
public static InetAddress getBroadcast(InetAddress myIpAddress) {

        NetworkInterface temp;
        InetAddress iAddr = null;
        try {
            temp = NetworkInterface.getByInetAddress(myIpAddress);
            List<InterfaceAddress> addresses = temp.getInterfaceAddresses();

            for (InterfaceAddress inetAddress : addresses) {
                iAddr = inetAddress.getBroadcast();
            }
            System.out.println("iAddr=" + iAddr);
            return iAddr;

        } catch (SocketException e) {

            e.printStackTrace();
            System.out.println("getBroadcast" + e.getMessage());
        }
        return null;
    }
 
開發者ID:RapidProjectH2020,項目名稱:rapid-linux,代碼行數:22,代碼來源:Util.java

示例5: getLocalCidrs

import java.net.InterfaceAddress; //導入依賴的package包/類
public static String[] getLocalCidrs() {
    final String defaultHostIp = getDefaultHostIp();

    final List<String> cidrList = new ArrayList<>();
    try {
        for (final NetworkInterface ifc : IteratorUtil.enumerationAsIterable(NetworkInterface.getNetworkInterfaces())) {
            if (ifc.isUp() && !ifc.isVirtual() && !ifc.isLoopback()) {
                for (final InterfaceAddress address : ifc.getInterfaceAddresses()) {
                    final InetAddress addr = address.getAddress();
                    final int prefixLength = address.getNetworkPrefixLength();
                    if (prefixLength < MAX_CIDR && prefixLength > 0) {
                        final String ip = addr.getHostAddress();
                        if (ip.equalsIgnoreCase(defaultHostIp)) {
                            cidrList.add(ipAndNetMaskToCidr(ip, getCidrNetmask(prefixLength)));
                        }
                    }
                }
            }
        }
    } catch (final SocketException e) {
        s_logger.warn("UnknownHostException in getLocalCidrs().", e);
    }

    return cidrList.toArray(new String[0]);
}
 
開發者ID:MissionCriticalCloud,項目名稱:cosmic,代碼行數:26,代碼來源:NetUtils.java

示例6: getPrivateInetInetAddress

import java.net.InterfaceAddress; //導入依賴的package包/類
public static final List<InetAddress> getPrivateInetInetAddress() throws SocketException {
    List<InetAddress> inetAddresses = new LinkedList<>();
    for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
        NetworkInterface netInterface = e.nextElement();
        if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
            continue;
        }

        for (InterfaceAddress address : netInterface.getInterfaceAddresses()) {
            InetAddress inetAddress = address.getAddress();
            if (inetAddress.isSiteLocalAddress() && !inetAddress.isLoopbackAddress()
                    && (inetAddress instanceof Inet4Address)) {
                inetAddresses.add(inetAddress);
            }
        }
    }

    return inetAddresses;
}
 
開發者ID:dinstone,項目名稱:jrpc,代碼行數:20,代碼來源:NetworkAddressUtil.java

示例7: getPublicInetInetAddress

import java.net.InterfaceAddress; //導入依賴的package包/類
public static final List<InetAddress> getPublicInetInetAddress() throws SocketException {
    List<InetAddress> inetAddresses = new LinkedList<>();
    for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) {
        NetworkInterface netInterface = e.nextElement();
        if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
            continue;
        }

        for (InterfaceAddress address : netInterface.getInterfaceAddresses()) {
            InetAddress inetAddress = address.getAddress();
            if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress()
                    && !inetAddress.isSiteLocalAddress() && (inetAddress instanceof Inet4Address)) {
                inetAddresses.add(inetAddress);
            }
        }
    }

    return inetAddresses;
}
 
開發者ID:dinstone,項目名稱:jrpc,代碼行數:20,代碼來源:NetworkAddressUtil.java

示例8: getDataNodeAddress

import java.net.InterfaceAddress; //導入依賴的package包/類
public static InetSocketAddress getDataNodeAddress() throws IOException {
	String ifname = TcpStorageConstants.STORAGE_TCP_INTERFACE;
	int port = TcpStorageConstants.STORAGE_TCP_PORT;
	
	NetworkInterface netif = NetworkInterface.getByName(ifname);
	if (netif == null){
		return null;
	}
	List<InterfaceAddress> addresses = netif.getInterfaceAddresses();
	InetAddress addr = null;
	for (InterfaceAddress address: addresses){
		if (address.getBroadcast() != null){
			InetAddress _addr = address.getAddress();
			addr = _addr;
		}
	}		
	InetSocketAddress inetAddr = new InetSocketAddress(addr, port);
	return inetAddr;
}
 
開發者ID:zrlio,項目名稱:crail,代碼行數:20,代碼來源:TcpStorageServer.java

示例9: getDataNodeAddress

import java.net.InterfaceAddress; //導入依賴的package包/類
public static InetSocketAddress getDataNodeAddress() throws IOException {
		String ifname = RdmaConstants.STORAGE_RDMA_INTERFACE;
		int port = RdmaConstants.STORAGE_RDMA_PORT;
		
		NetworkInterface netif = NetworkInterface.getByName(ifname);
		if (netif == null){
			return null;
		}
		List<InterfaceAddress> addresses = netif.getInterfaceAddresses();
		InetAddress addr = null;
		for (InterfaceAddress address: addresses){
//			LOG.info("address* " + address.toString() + ", _addr " + _addr.toString() + ", isSiteLocal " + _addr.isSiteLocalAddress() + ", tmp " + tmp + ", size " + tmp.length + ", broadcast " + address.getBroadcast());
			if (address.getBroadcast() != null){
				InetAddress _addr = address.getAddress();
				addr = _addr;
			}
		}		
		InetSocketAddress inetAddr = new InetSocketAddress(addr, port);
		return inetAddr;
	}
 
開發者ID:zrlio,項目名稱:crail,代碼行數:21,代碼來源:RdmaStorageServer.java

示例10: sendBroadcastRequest

import java.net.InterfaceAddress; //導入依賴的package包/類
private void sendBroadcastRequest(InterfaceAddress ia) {
    try {
        // add to my address list
        myAddress.add(ia.getAddress().getHostAddress());
        // data to send
        byte[] sendData = Commons.toBytes(mDataToSend);
        // Send the broadcast package!  
        for (int port : SubnetServer.PORTS) {
            DatagramPacket sendPacket = new DatagramPacket(
                    sendData, sendData.length,
                    ia.getBroadcast(), port);
            mSocket.send(sendPacket);
        }

    } catch (Exception ex) {
        Logs.error(getClass(), "Failed to send broadcast. {0}", ex);
    }
}
 
開發者ID:dipu-bd,項目名稱:Tuntuni,代碼行數:19,代碼來源:Subnet.java

示例11: firstLocalNonLoopbackIpv4Address

import java.net.InterfaceAddress; //導入依賴的package包/類
/**
 * @deprecated This method is no longer used by LittleProxy and may be removed in a future release.
 */
@Deprecated
public static InetAddress firstLocalNonLoopbackIpv4Address() {
    try {
        Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
                .getNetworkInterfaces();
        while (networkInterfaces.hasMoreElements()) {
            NetworkInterface networkInterface = networkInterfaces
                    .nextElement();
            if (networkInterface.isUp()) {
                for (InterfaceAddress ifAddress : networkInterface
                        .getInterfaceAddresses()) {
                    if (ifAddress.getNetworkPrefixLength() > 0
                            && ifAddress.getNetworkPrefixLength() <= 32
                            && !ifAddress.getAddress().isLoopbackAddress()) {
                        return ifAddress.getAddress();
                    }
                }
            }
        }
        return null;
    } catch (SocketException se) {
        return null;
    }
}
 
開發者ID:wxyzZ,項目名稱:little_mitm,代碼行數:28,代碼來源:NetworkUtils.java

示例12: getBroadcast

import java.net.InterfaceAddress; //導入依賴的package包/類
public static InetAddress getBroadcast(InetAddress myIpAddress) {

    NetworkInterface temp;
    InetAddress iAddr = null;
    try {
      temp = NetworkInterface.getByInetAddress(myIpAddress);
      List<InterfaceAddress> addresses = temp.getInterfaceAddresses();

      for (InterfaceAddress inetAddress : addresses) {
        iAddr = inetAddress.getBroadcast();
      }
      Log.d(TAG, "iAddr=" + iAddr);
      return iAddr;

    } catch (SocketException e) {

      e.printStackTrace();
      Log.d(TAG, "getBroadcast" + e.getMessage());
    }
    return null;
  }
 
開發者ID:RapidProjectH2020,項目名稱:offloading-framework-android,代碼行數:22,代碼來源:Utils.java

示例13: getAllServerAddress

import java.net.InterfaceAddress; //導入依賴的package包/類
protected static List<InetAddress> getAllServerAddress() {

		List<InetAddress> result = new LinkedList<>();

		try {
			Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
			if (interfaces == null) {
				return null;
			}
			while (interfaces.hasMoreElements()) {
				NetworkInterface current = interfaces.nextElement();
				List<InterfaceAddress> addresses = current.getInterfaceAddresses();
				if (addresses.size() == 0) {
					continue;
				}
				for (InterfaceAddress interfaceAddress : addresses) {
					InetAddress address = interfaceAddress.getAddress();
					result.add(address);
				}
			}
		} catch (SocketException e) {
		}
		return result;
	}
 
開發者ID:ctripcorp,項目名稱:x-pipe,代碼行數:25,代碼來源:IpUtils.java

示例14: getBroadcastAddress

import java.net.InterfaceAddress; //導入依賴的package包/類
public static String getBroadcastAddress() {
    System.setProperty("java.net.preferIPv4Stack", "true");
    try {
        for (Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces(); niEnum
                .hasMoreElements(); ) {
            NetworkInterface ni = niEnum.nextElement();
            if (!ni.isLoopback()) {
                for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) {
                    if (interfaceAddress.getBroadcast() != null) {
                        L.d(TAG, interfaceAddress.getBroadcast().toString().substring(1));
                        return interfaceAddress.getBroadcast().toString().substring(1);
                    }
                }
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }

    return null;
}
 
開發者ID:hanks-zyh,項目名稱:FlyWoo,代碼行數:22,代碼來源:WifiUtils.java

示例15: getLocalAddress

import java.net.InterfaceAddress; //導入依賴的package包/類
public final InetAddress getLocalAddress() throws SocketException {
  for (final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces
      .hasMoreElements();) {
    final NetworkInterface networkInterface = interfaces.nextElement();
    if (networkInterface.isLoopback()) {
      continue;
    }
    for (final InterfaceAddress interfaceAddr : networkInterface.getInterfaceAddresses()) {
      final InetAddress inetAddr = interfaceAddr.getAddress();
      if (!(inetAddr instanceof Inet4Address)) {
        continue;
      }
      return inetAddr;
    }
  }
  return null;
}
 
開發者ID:rquast,項目名稱:swingsane,代碼行數:18,代碼來源:DiscoveryJob.java


注:本文中的java.net.InterfaceAddress類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。