本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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()]);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}