Setting Multicast Time To Live in Java 规格严格

http://www.peterfranza.com/2008/09/25/setting-multicast-time-to-live-in-java/

http://docs.oracle.com/javase/1.4.2/docs/guide/net/properties.html

http://www.cnblogs.com/lganggang131/archive/2012/02/13/2349740.html

http://javapub.iteye.com/category/107501?page=2

java.security.Security.setProperty("networkaddress.cache.ttl" , "60"); Amazon WebService.

http://www.0x13.de/index.php/tools.html

http://zhujinhuant-hotmail-com.iteye.com/blog/1040214

------------------------------------------------------------------------

http://code.google.com/p/bitcoinj/w/list
http://www.java-tips.org/java-se-tips/java.net/how-do-i-use-java-to-ping-a-host.html

http://www.davidreilly.com/java/java_network_programming/#3.5

http://www.blogjava.net/zhanglongsr/archive/2012/02/07/369543.html

 http://www.jguru.com/faq/view.jsp?EID=1274376

I have read this a few other places as well, but InetAddress.isReachable() instance method actually attempts a TCP 3-way handshake with the host's port 7 (Echo). If it cannot complete the handshake (SYN -> SYN,ACK -> ACK)) or does not get a reply (JavaDocs don't specify which) before the timeout specified, it returns false.

This is vastly different from an ICMP Ping, which sends ICMP Type 8 (echo) to the host and awaits an ICMP Type 0 (echo reply).

So, if the server is not listening on Port 7, isReachable(int) returns false, while if the network link is up, a Ping will receive a reply.

However, public boolean isReachable(NetworkInterface netif, int ttl, int timeout) will attempt an ICMP Echo (PING).

这个是正确的,我用wiresharks抓包验证了。

 public static boolean DoPing(String ipstr) {
  boolean retv = false;
  try {
   InputStream ins = Runtime.getRuntime()
     .exec("ping -n 1 -w 2000 " + ipstr).getInputStream();
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   int a = -1;
   while ((a = ins.read()) != -1) {
    out.write(a);
   }
   System.out.println(new String(out.toByteArray()));
   String parsstr = new StringTokenizer(new String(out.toByteArray()),
     "%").nextToken().trim();
   if (!parsstr.endsWith("100"))
    retv = true;
  } catch (Exception e) {
   e.printStackTrace();
   retv = false;
  }
  return retv;

原文地址:https://www.cnblogs.com/diyunpeng/p/2513016.html