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


Java InetAddress.isReachable方法代码示例

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


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

示例1: doInBackground

import java.net.InetAddress; //导入方法依赖的package包/类
@Override
protected String doInBackground(String... strings) {
    try {
        String address = strings[0];
        InetAddress inetAddress = InetAddress.getByName(address);
        if (inetAddress != null && inetAddress.isReachable(100)){
            ip = inetAddress.getHostAddress();
            deviceFound = true;
            selfFound = selfIp.equals(ip);

            if (!selfFound) {
                NbtAddress[] addressList = NbtAddress.getAllByAddress(address);
                NbtAddress nbtAddress = addressList[0];
                if (address != null) {
                    deviceName = nbtAddress.getHostName();
                }
            }
        }
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
    }
    return null;
}
 
开发者ID:MBach,项目名称:home-automation,代码行数:24,代码来源:AsyncNetworkRequest.java

示例2: isValid

import java.net.InetAddress; //导入方法依赖的package包/类
@Override
public boolean isValid(ClusterNode localNode) {
    try {
        InetAddress address = InetAddress.getByName(host);

        boolean reachable = address.isReachable(timeout);

        if (reachable) {
            if (DEBUG) {
                log.debug("Address reachability check success [host={}, timeout={}]", host, timeout);
            }
        } else {
            log.warn("Address reachability check failed [host={}, timeout={}]", host, timeout);
        }

        return reachable;
    } catch (IOException e) {
        log.warn("Address reachability check failed with an error [host={}, timeout={}, cause={}]", host, timeout, e.toString());
    }

    return false;
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:23,代码来源:HostReachabilityDetector.java

示例3: isReachable

import java.net.InetAddress; //导入方法依赖的package包/类
private boolean isReachable(InetAddress address, int timeOutMillis) throws Exception {
	if (isWindowsOS) {
		return address.isReachable(timeOutMillis);
	}
	Process p = new ProcessBuilder("ping", "-c", "1", address.getHostAddress()).start();
	try {
		p.waitFor(timeOutMillis, TimeUnit.MILLISECONDS);
	} catch (InterruptedException e) {
		return false;
	}
	if (p.isAlive()){
		return false;
	}
	int exitValue = p.exitValue();
	logger.trace("exit value: {}", exitValue);

	return exitValue == 0;
}
 
开发者ID:comtel2000,项目名称:mokka7,代码行数:19,代码来源:PingWatchdogService.java

示例4: pingButtonActionPerformed

import java.net.InetAddress; //导入方法依赖的package包/类
private void pingButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pingButtonActionPerformed
       String host = hostTF.getText();
     try {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        InetAddress adr = Inet4Address.getByName(host);
        try{
            adr.isReachable(3000);
            JOptionPane.showMessageDialog(this, host+" is reachable, but it may not be the SpiNNaker!");
        }catch(IOException notReachable){
            JOptionPane.showMessageDialog(this, host+" is not reachable: "+notReachable.toString(), "Not reachable", JOptionPane.WARNING_MESSAGE);
        }
    } catch (UnknownHostException ex) {
              JOptionPane.showMessageDialog(this, host+" is unknown host: "+ex.toString(), "Host not found", JOptionPane.WARNING_MESSAGE);
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }

}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:19,代码来源:SpiNNaker_InterfaceFactory.java

示例5: pingButtonActionPerformed

import java.net.InetAddress; //导入方法依赖的package包/类
private void pingButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pingButtonActionPerformed
    String host = hostTF.getText();
    try {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        InetAddress adr = Inet4Address.getByName(host);
        try {
            adr.isReachable(3000);
            JOptionPane.showMessageDialog(this, host + " is reachable. However it may not be the eDVS!");
        } catch (IOException notReachable) {
            JOptionPane.showMessageDialog(this, host + " is not reachable: " + notReachable.toString(), "Not reachable", JOptionPane.WARNING_MESSAGE);
        }
    } catch (UnknownHostException ex) {
        JOptionPane.showMessageDialog(this, host + " is unknown host: " + ex.toString(), "Host not found", JOptionPane.WARNING_MESSAGE);
    } finally {
        setCursor(Cursor.getDefaultCursor());
    }

}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:19,代码来源:eDVS128_InterfaceFactory.java

示例6: pingDevice

import java.net.InetAddress; //导入方法依赖的package包/类
private int pingDevice(NetworkDevice dev) throws IOException {

        InetAddress adr;
        if (dev.getHostname() != null) {
            adr = InetAddress.getByName(dev.getHostname());
        } else {
            adr = InetAddress.getByName(dev.getIp());
        }
        long start = System.currentTimeMillis();
        if (adr.isReachable(TIMEOUT_PING)) {
            long time = System.currentTimeMillis() - start;
            if (time == 0) {
                // special case, make sure that 0 is not returned when reachable
                return 1;
            }
            return (int) time;
        }
        return 0;

    }
 
开发者ID:dainesch,项目名称:HueSense,代码行数:21,代码来源:LanComm.java

示例7: getConfigStatus

import java.net.InetAddress; //导入方法依赖的package包/类
@Override
public Collection<ConfigStatusMessage> getConfigStatus() {

    Collection<ConfigStatusMessage> configStatus = new ArrayList<>();

    try {
        InetAddress ip = InetAddress.getByName(plug.ip);
        if (!ip.isReachable(500)) {
            configStatus.add(
                    ConfigStatusMessage.Builder.error("offline").withMessageKeySuffix("ip unreachable").build());
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR);
        }
    } catch (IOException e) {
        logger.debug("Communication error ocurred reaching the device ", e);
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, e.getMessage());
    }

    return configStatus;
}
 
开发者ID:computerlyrik,项目名称:openhab2-addon-hs110,代码行数:20,代码来源:HS110Handler.java

示例8: main

import java.net.InetAddress; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
    if (System.getProperty("os.name").startsWith("Windows")) {
        return;
    }

    boolean preferIPv4Stack = "true".equals(System
            .getProperty("java.net.preferIPv4Stack"));
    List<String> addrs = new ArrayList<String>();
    InetAddress inetAddress = null;

    addrs.add("0.0.0.0");
    if (!preferIPv4Stack) {
        if (hasIPv6()) {
            addrs.add("::0");
        }
    }

    for (String addr : addrs) {
        inetAddress = InetAddress.getByName(addr);
        System.out.println("The target ip is "
                + inetAddress.getHostAddress());
        boolean isReachable = inetAddress.isReachable(3000);
        System.out.println("the target is reachable: " + isReachable);
        if (isReachable) {
            System.out.println("Test passed ");
        } else {
            System.out.println("Test failed ");
            throw new Exception("address " + inetAddress.getHostAddress()
                    + " can not be reachable!");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:PingThis.java

示例9: establishConnection

import java.net.InetAddress; //导入方法依赖的package包/类
@Override
protected void establishConnection(InetAddress... addr) {
  for(InetAddress address : addr) {
    if(address != null) {
      try {
        boolean reachable = address.isReachable(2000);
        if(reachable) {
          establishConnection(address);
          break;
        }
      } catch (IOException e) {
        mLog.exception(e);
      }
    }
  }
}
 
开发者ID:flybotix,项目名称:highfrequencyrobots,代码行数:17,代码来源:UDPSender.java

示例10: getPingToIP

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * pings an ip address
 *
 * @param ipToPingNowPleaseGiveThisWhyIsThisFieldDescriptorSoLongLolEksDee idk lol
 * @return the ping
 */
public static String getPingToIP(String ipToPingNowPleaseGiveThisWhyIsThisFieldDescriptorSoLongLolEksDee) {
    try {
        InetAddress inet = InetAddress.getByName(ipToPingNowPleaseGiveThisWhyIsThisFieldDescriptorSoLongLolEksDee);

        long finish = 0;
        long start = new GregorianCalendar().getTimeInMillis();

        if (inet.isReachable(2500)) {
            finish = new GregorianCalendar().getTimeInMillis();
            return finish - start + " ms";
        } else {
            return "-1 ms";
        }
    } catch (Exception e) {
        //System.out.println("Exception:" + e.getMessage());
    }

    return "-1 ms";
}
 
开发者ID:CyR1en,项目名称:Minecordbot,代码行数:26,代码来源:MCPing.java

示例11: main

import java.net.InetAddress; //导入方法依赖的package包/类
public static void main(String[] args) {
    try {
        InetAddress addr = InetAddress.getByName("localhost");
        if (!addr.isReachable(10000))
            throw new RuntimeException("Localhost should always be reachable");
        NetworkInterface inf = NetworkInterface.getByInetAddress(addr);
        if (inf != null) {
            if (!addr.isReachable(inf, 20, 10000))
            throw new RuntimeException("Localhost should always be reachable");
        }

    } catch (IOException e) {
        throw new RuntimeException("Unexpected exception:" + e);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:IsReachable.java

示例12: isPresent

import java.net.InetAddress; //导入方法依赖的package包/类
public boolean isPresent() {

        try {

            InetAddress ip = InetAddress.getByName(this.ip);
            return ip.isReachable(500);
        } catch (IOException ignore) {
            // ignore this failing and return false
        }
        return false;
    }
 
开发者ID:computerlyrik,项目名称:openhab2-addon-hs110,代码行数:12,代码来源:HS110.java

示例13: isIPReachable

import java.net.InetAddress; //导入方法依赖的package包/类
public static boolean isIPReachable(String ipStr, int timeout) {

        try {
            InetAddress inetAddress = InetAddress.getByName(ipStr);

            if (inetAddress.isReachable(timeout)) {
                return true;
            }
        }
        catch (Exception e) {
            // ignore
        }

        return false;
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:16,代码来源:NetworkHelper.java


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