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


Java InterfaceAddress.getBroadcast方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: isBroadcastAddressAvailable

import java.net.InterfaceAddress; //導入方法依賴的package包/類
private boolean isBroadcastAddressAvailable(NetworkInterface networkInterface) {
   try
   {
      for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses())
      {
         InetAddress broadcast = interfaceAddress.getBroadcast();
         if (broadcast != null)
         {
            return true;
         }
      }
   }
   catch (Throwable e)
   {
      //in case networkInterface.getInterfaceAddresses() throws NPE on windows
   }
   return false;
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:19,代碼來源:UDPEndpointAPITestCase.java

示例9: getBroadcastAddresses

import java.net.InterfaceAddress; //導入方法依賴的package包/類
public String[] getBroadcastAddresses() {
    ArrayList<String> list = new ArrayList<>();
    try {
        System.setProperty("java.net.preferIPv4Stack", "true");
        Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces();

        while (niEnum.hasMoreElements()) {
            NetworkInterface ni = niEnum.nextElement();

            if (!ni.isLoopback()) {
                for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses()) {
                    if (interfaceAddress.getBroadcast() != null)
                        list.add(interfaceAddress.getBroadcast().toString().substring(1));
                }
            }
        }
    } catch (Exception ignored) {
    }
    return list.toArray(new String[list.size()]);
}
 
開發者ID:KsyMC,項目名稱:ForgePE,代碼行數:21,代碼來源:MainActivity.java

示例10: findBroadcastAddress

import java.net.InterfaceAddress; //導入方法依賴的package包/類
private static InetAddress findBroadcastAddress() {
	try {
		ArrayList<NetworkInterface> ifaces = Collections.list(NetworkInterface.getNetworkInterfaces());

		for (NetworkInterface i : ifaces) {
			if (!i.isLoopback()) {
				List<InterfaceAddress> addresses = i.getInterfaceAddresses();
				for (InterfaceAddress a : addresses) {
					if (a.getAddress() instanceof Inet4Address) {
						return a.getBroadcast();
					}
				}
			}
		}
	} catch (SocketException e) {
		Logger.log("unable to do network stuff.", e);
	}
	
	return null;
}
 
開發者ID:akrs,項目名稱:AndroidLIFX,代碼行數:21,代碼來源:TestCMD.java

示例11: getBroadcastAddress

import java.net.InterfaceAddress; //導入方法依賴的package包/類
public static InetAddress getBroadcastAddress() {
	try {
		Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
		while (interfaces.hasMoreElements()) {
			NetworkInterface networkInterface = interfaces.nextElement();
			if (networkInterface.isLoopback()) continue;
			for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses()) {
				InetAddress broadcast = interfaceAddress.getBroadcast();
				if (broadcast != null) return broadcast;
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:Dakror,項目名稱:Arise,代碼行數:17,代碼來源:Assistant.java

示例12: getBroadcastAddresses

import java.net.InterfaceAddress; //導入方法依賴的package包/類
public List<InetAddress> getBroadcastAddresses() throws SocketException {
	final List<InetAddress> broadcastAddresses = new ArrayList<InetAddress>();
	final Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
	while (e.hasMoreElements()) {
		final NetworkInterface nic = e.nextElement();
		if (!nic.isLoopback()) {
			for (InterfaceAddress ifaceAddress : nic.getInterfaceAddresses()) {
				InetAddress broadcast = ifaceAddress.getBroadcast();
				if (broadcast != null) {
					broadcastAddresses.add(broadcast);
				}
			}
		}
	}
	return broadcastAddresses;
}
 
開發者ID:kmbulebu,項目名稱:NickNack,代碼行數:17,代碼來源:WakeOnLan.java

示例13: getBroadcast

import java.net.InterfaceAddress; //導入方法依賴的package包/類
public static InetAddress getBroadcast(){
InetAddress found_bcast_address=null;
 System.setProperty("java.net.preferIPv4Stack", "true"); 
    try
    {
      Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces();
      while (niEnum.hasMoreElements())
      {
        NetworkInterface ni = niEnum.nextElement();
        if(!ni.isLoopback()){
            for (InterfaceAddress interfaceAddress : ni.getInterfaceAddresses())
            {
              found_bcast_address = interfaceAddress.getBroadcast();               
            }
        }
      }
    }
    catch (SocketException e)
    {
      e.printStackTrace();
    }

    return found_bcast_address;
}
 
開發者ID:screenfreeze,項目名稱:deskcon-android,代碼行數:25,代碼來源:DesktopHostsActivity.java

示例14: getBroadcastWhenTether

import java.net.InterfaceAddress; //導入方法依賴的package包/類
public InetAddress getBroadcastWhenTether(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;
	}
 
開發者ID:fabriph,項目名稱:peer-instruction,代碼行數:22,代碼來源:UDPClient.java

示例15: 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) {
                        logger.d(interfaceAddress.getBroadcast().toString().substring(1));
                        return interfaceAddress.getBroadcast().toString().substring(1);
                    }
                }
            }
        }
    }
    catch (SocketException e) {
        e.printStackTrace();
    }

    return null;
}
 
開發者ID:hillfly,項目名稱:WifiChat,代碼行數:23,代碼來源:WifiUtils.java


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