public InetAddress getBroadcastAddress(InetAddress inetAddress) { synchronized (networkInterfaces) { for (NetworkInterface iface : networkInterfaces) { for (InterfaceAddress interfaceAddress : getInterfaceAddresses(iface)) { if (interfaceAddress != null && interfaceAddress.getAddress().equals(inetAddress)) { return interfaceAddress.getBroadcast(); } } } } return null; }
log.info(" Broadcast: " + interfaceAddress.getBroadcast()); log.info(" Prefix length: " + interfaceAddress.getNetworkPrefixLength());
InetAddress addr = ifaceAddr.getAddress(); if (addr instanceof Inet4Address) { bcastInetAddr = ifaceAddr.getBroadcast(); break;
public InetAddress getBroadcast(InetAddress inetAddr) { NetworkInterface temp; InetAddress iAddr = null; try { temp = NetworkInterface.getByInetAddress(inetAddr); 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; }
public InetAddress getBroadcastAddress(InetAddress inetAddress) { synchronized (networkInterfaces) { for (NetworkInterface iface : networkInterfaces) { for (InterfaceAddress interfaceAddress : getInterfaceAddresses(iface)) { if (interfaceAddress != null && interfaceAddress.getAddress().equals(inetAddress)) { return interfaceAddress.getBroadcast(); } } } } return null; }
/** * Get all broadcast addresses on the current host * * @return list of broadcast addresses, empty list if no broadcast addresses found */ public static List<String> getAllBroadcastAddresses() { List<String> broadcastAddresses = new LinkedList<String>(); try { final Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { final NetworkInterface networkInterface = networkInterfaces.nextElement(); final List<InterfaceAddress> interfaceAddresses = networkInterface.getInterfaceAddresses(); for (InterfaceAddress interfaceAddress : interfaceAddresses) { final InetAddress addr = interfaceAddress.getAddress(); if (addr instanceof Inet4Address && !addr.isLinkLocalAddress() && !addr.isLoopbackAddress()) { InetAddress broadcast = interfaceAddress.getBroadcast(); if (broadcast != null) { broadcastAddresses.add(broadcast.getHostAddress()); } } } } } catch (SocketException ex) { LOGGER.error("Could not find broadcast address: {}", ex.getMessage(), ex); } return broadcastAddresses; }
addr.getBroadcast( ).getHostAddress( ) );
(byte) (netmask & 0xFF) }))); InetAddress broadcast = interfaceAddress.getBroadcast(); if (broadcast != null) { sb.append(" broadcast:").append(NetworkAddress.format(broadcast));
log.info(" Broadcast: " + interfaceAddress.getBroadcast()); log.info(" Prefix length: " + interfaceAddress.getNetworkPrefixLength());
public static String getBroadcast() throws SocketException { System.setProperty("java.net.preferIPv4Stack", "true"); for( Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces.hasMoreElements(); ) { NetworkInterface nif = interfaces.nextElement(); if( !nif.isLoopback() ) { for( InterfaceAddress addr : nif.getInterfaceAddresses() ) { return addr.getBroadcast().toString().substring(1); } } } return null; }
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (InterfaceAddress address : intf.getInterfaceAddresses()) { System.out.println(address.getBroadcast().toString().substring(1));; } }
/** * 获得广播地址 * @return */ public String getBroadcastAddress(){ InterfaceAddress addr=net.getInterfaceAddresses().get(0); return addr.getBroadcast().getHostAddress(); } /**
private static IpAddress broadcast(InterfaceAddress address) { InetAddress broadcast = address.getBroadcast(); return broadcast != null ? IpAddress.of(broadcast) : BROADCAST; }
private static IpAddress broadcast(InterfaceAddress address) { InetAddress broadcast = address.getBroadcast(); return broadcast != null ? IpAddress.of(broadcast) : BROADCAST; }
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface networkInterface = interfaces.nextElement(); if (networkInterface.isLoopback()) continue; // Do not want to use the loopback interface. for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses()) { InetAddress broadcast = interfaceAddress.getBroadcast(); if (broadcast == null) continue; // Do something with the address. } }
InetAddress localhost = InetAddress.getLocalHost(); NetworkInterface iFace = NetworkInterface.getByInetAddress(localhost); int prefix = iFace.getInterfaceAddresses().get(0).getNetworkPrefixLength(); InetAddress bcastAddress = iFace.getInterfaceAddresses().get(0).getBroadcast(); int addrSize = localhost.getAddress().length * 8; byte[] maskBytes = new byte[localhost.getAddress().length]; for (int i = 0; i < prefix; ++i) { maskBytes[i / 8] |= 1 << (7 - i % 8); } byte[] net = Arrays.copyOf(localhost.getAddress(), localhost.getAddress().length); for (int i = 0; i < net.length; ++i) { net[i] = (byte)(net[i] & maskBytes[i]); } InetAddress networkAddress = InetAddress.getByAddress(net);
public InetAddress getBroadcastAddress(InetAddress inetAddress) { synchronized (networkInterfaces) { for (NetworkInterface iface : networkInterfaces) { for (InterfaceAddress interfaceAddress : getInterfaceAddresses(iface)) { if (interfaceAddress != null && interfaceAddress.getAddress().equals(inetAddress)) { return interfaceAddress.getBroadcast(); } } } } return null; }
private static InetAddress getFirstActiveBroadcast() throws SocketException { NetworkInterface iface = getFirstActiveIPv4Interface(); for(InterfaceAddress ifaceAddr: iface.getInterfaceAddresses()) { InetAddress addr = ifaceAddr.getAddress(); if(addr instanceof Inet4Address) { return ifaceAddr.getBroadcast(); } } return null; }
public static InterfaceAddress copyOf(java.net.InterfaceAddress mutable) { Builder builder = builder(); builder.withAddress(InetAddress.copyOf(mutable.getAddress())); if (mutable.getBroadcast() != null) { InetAddress broadcast = InetAddress.copyOf(mutable.getBroadcast()); builder.withBroadcast(Optional.of(broadcast)); } builder.withNetworkPrefixLength(mutable.getNetworkPrefixLength()); return builder.build(); }
public Ifaddr(Ruby runtime, RubyClass metaClass, NetworkInterface ni, InterfaceAddress it) throws Exception { super(runtime, metaClass); this.isUp = ni.isUp(); this.name = ni.getDisplayName(); this.isLoopback = ni.isLoopback(); this.isPointToPoint = ni.isPointToPoint(); this.networkInterface = ni; this.isLink = false; this.address = it.getAddress(); this.broadcast = it.getBroadcast(); this.interfaceAddress = it; setAddr(runtime); setNetmask(it); setIndex(ni); setInspectString(ni); }