亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ping.java

?? Java實現Ping功能(采用JNI技術)
?? JAVA
字號:
/* * $Id: Ping.java 8033 2007-09-03 04:02:36Z dfs $ * * Copyright 2004-2007 Daniel F. Savarese * Contact Information: http://www.savarese.org/contact.html * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.savarese.org/software/ApacheLicense-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package example;import java.io.IOException;import java.net.InetAddress;import java.net.Inet6Address;import java.util.Enumeration;import java.util.concurrent.*;import org.savarese.vserv.tcpip.*;import org.savarese.rocksaw.net.RawSocket;import static org.savarese.rocksaw.net.RawSocket.PF_INET;import static org.savarese.rocksaw.net.RawSocket.PF_INET6;import static org.savarese.rocksaw.net.RawSocket.getProtocolByName;import static org.savarese.vserv.tcpip.ICMPPacket.OFFSET_ICMP_CHECKSUM;/** * <p>The Ping class is a simple demo showing how you can send * ICMP echo requests and receive echo replies using raw sockets. * It has been updated to work with both IPv4 and IPv6.</p> * * <p>Note, this is not a model of good programming.  The point * of the example is to show how the RawSocket API calls work.  There * is much kluginess surrounding the actual packet and protocol * handling, all of which is outside of the scope of what RockSaw * does.</p> *  * @author <a href="http://www.savarese.org/">Daniel F. Savarese</a> */public class Ping {  public static interface EchoReplyListener {    public void notifyEchoReply(ICMPEchoPacket packet,                                byte[] data, int dataOffset,                                byte[] srcAddress)      throws IOException;  }  public static class Pinger {    private static final int TIMEOUT = 10000;    protected RawSocket socket;    protected ICMPEchoPacket sendPacket, recvPacket;    protected int offset, length, dataOffset;    protected int requestType, replyType;    protected byte[] sendData, recvData, srcAddress;    protected int sequence, identifier;    protected EchoReplyListener listener;    protected Pinger(int id, int protocolFamily, int protocol)      throws IOException    {      sequence   = 0;      identifier = id;      setEchoReplyListener(null);      sendPacket = new ICMPEchoPacket(1);      recvPacket = new ICMPEchoPacket(1);      sendData = new byte[84];      recvData = new byte[84];      sendPacket.setData(sendData);      recvPacket.setData(recvData);      sendPacket.setIPHeaderLength(5);      recvPacket.setIPHeaderLength(5);      sendPacket.setICMPDataByteLength(56);      recvPacket.setICMPDataByteLength(56);      offset     = sendPacket.getIPHeaderByteLength();      dataOffset = offset + sendPacket.getICMPHeaderByteLength();      length     = sendPacket.getICMPPacketByteLength();      socket = new RawSocket();      socket.open(protocolFamily, protocol);      try {        socket.setSendTimeout(TIMEOUT);        socket.setReceiveTimeout(TIMEOUT);      } catch(java.net.SocketException se) {        socket.setUseSelectTimeout(true);        socket.setSendTimeout(TIMEOUT);        socket.setReceiveTimeout(TIMEOUT);      }    }    public Pinger(int id) throws IOException {      this(id, PF_INET, getProtocolByName("icmp"));      srcAddress  = new byte[4];      requestType = ICMPPacket.TYPE_ECHO_REQUEST;      replyType   = ICMPPacket.TYPE_ECHO_REPLY;    }    protected void computeSendChecksum(InetAddress host)      throws IOException    {      sendPacket.computeICMPChecksum();    }    public void setEchoReplyListener(EchoReplyListener l) {      listener = l;    }    /**     * Closes the raw socket opened by the constructor.  After calling     * this method, the object cannot be used.     */    public void close() throws IOException {      socket.close();    }    public void sendEchoRequest(InetAddress host) throws IOException {      sendPacket.setType(requestType);      sendPacket.setCode(0);      sendPacket.setIdentifier(identifier);      sendPacket.setSequenceNumber(sequence++);      OctetConverter.longToOctets(System.nanoTime(), sendData, dataOffset);      computeSendChecksum(host);      socket.write(host, sendData, offset, length);    }    public void receive() throws IOException {      socket.read(recvData, srcAddress);    }    public void receiveEchoReply() throws IOException {      do {        receive();      } while(recvPacket.getType() != replyType ||              recvPacket.getIdentifier() != identifier);      if(listener != null)        listener.notifyEchoReply(recvPacket, recvData, dataOffset, srcAddress);    }    /**     * Issues a synchronous ping.     *     * @param host The host to ping.     * @return The round trip time in nanoseconds.     */    public long ping(InetAddress host) throws IOException {      sendEchoRequest(host);      receiveEchoReply();      long end   = System.nanoTime();      long start = OctetConverter.octetsToLong(recvData, dataOffset);      return (end - start);    }    /**     * @return The number of bytes in the data portion of the ICMP ping request     * packet.     */    public int getRequestDataLength() {      return sendPacket.getICMPDataByteLength();    }    /** @return The number of bytes in the entire IP ping request packet. */    public int getRequestPacketLength() {      return sendPacket.getIPPacketLength();    }  }  public static class PingerIPv6 extends Pinger {    private static final int IPPROTO_ICMPV6           = 58;    private static final int ICMPv6_TYPE_ECHO_REQUEST = 128;    private static final int ICMPv6_TYPE_ECHO_REPLY   = 129;    /**     * Operating system kernels are supposed to calculate the ICMPv6     * checksum for the sender, but Microsoft's IPv6 stack does not do     * this.  Nor does it support the IPV6_CHECKSUM socket option.     * Therefore, in order to work on the Windows family of operating     * systems, we have to calculate the ICMPv6 checksum.     */    private static class ICMPv6ChecksumCalculator extends IPPacket {      ICMPv6ChecksumCalculator() { super(1); }      private int computeVirtualHeaderTotal(byte[] destination, byte[] source,                                            int icmpLength)      {        int total = 0;        for(int i = 0; i < source.length;)          total+=(((source[i++] & 0xff) << 8) | (source[i++] & 0xff));        for(int i = 0; i < destination.length;)          total+=(((destination[i++] & 0xff) << 8) | (destination[i++] & 0xff));        total+=(icmpLength >>> 16);        total+=(icmpLength & 0xffff);        total+=IPPROTO_ICMPV6;        return total;      }      int computeChecksum(byte[] data, ICMPPacket packet, byte[] destination,                          byte[] source)      {        int startOffset    = packet.getIPHeaderByteLength();        int checksumOffset = startOffset + OFFSET_ICMP_CHECKSUM;        int ipLength       = packet.getIPPacketLength();        int icmpLength     = packet.getICMPPacketByteLength();        setData(data);        return          _computeChecksum_(startOffset, checksumOffset, ipLength,                            computeVirtualHeaderTotal(destination, source,                                                      icmpLength), true);      }    }    private byte[] localAddress;    private ICMPv6ChecksumCalculator icmpv6Checksummer;    public PingerIPv6(int id) throws IOException {      //socket.open(protocolFamily,       super(id, PF_INET6, IPPROTO_ICMPV6 /*getProtocolByName("ipv6-icmp")*/);      icmpv6Checksummer = new ICMPv6ChecksumCalculator();      srcAddress   = new byte[16];      localAddress = new byte[16];      requestType  = ICMPv6_TYPE_ECHO_REQUEST;      replyType    = ICMPv6_TYPE_ECHO_REPLY;    }    protected void computeSendChecksum(InetAddress host)      throws IOException    {      // This is necessary only for Windows, which doesn't implement      // RFC 2463 correctly.      socket.getSourceAddressForDestination(host, localAddress);      icmpv6Checksummer.computeChecksum(sendData, sendPacket,                                        host.getAddress(), localAddress);    }    public void receive() throws IOException {      socket.read(recvData, offset, length, srcAddress);    }  }  public static final void main(String[] args) throws Exception {    if(args.length < 1 || args.length > 2) {      System.err.println("usage: Ping host [count]");      System.exit(1);    }    final ScheduledThreadPoolExecutor executor =      new ScheduledThreadPoolExecutor(2);    try{      final InetAddress address = InetAddress.getByName(args[0]);      final String hostname = address.getCanonicalHostName();      final String hostaddr = address.getHostAddress();      final int count;      // Ping programs usually use the process ID for the identifier,      // but we can't get it and this is only a demo.      final int id = 65535;      final Pinger ping;      if(args.length == 2)        count = Integer.parseInt(args[1]);      else        count = 5;      if(address instanceof Inet6Address)        ping = new Ping.PingerIPv6(id);      else        ping = new Ping.Pinger(id);      ping.setEchoReplyListener(new EchoReplyListener() {          StringBuffer buffer = new StringBuffer(128);          public void notifyEchoReply(ICMPEchoPacket packet,                                      byte[] data, int dataOffset,                                      byte[] srcAddress)            throws IOException          {            long end   = System.nanoTime();            long start = OctetConverter.octetsToLong(data, dataOffset);            // Note: Java and JNI overhead will be noticeable (100-200            // microseconds) for sub-millisecond transmission times.            // The first ping may even show several seconds of delay            // because of initial JIT compilation overhead.            double rtt = (double)(end - start) / 1e6;            buffer.setLength(0);            buffer.append(packet.getICMPPacketByteLength())              .append(" bytes from ").append(hostname).append(" (");            buffer.append(InetAddress.getByAddress(srcAddress).toString());            buffer.append("): icmp_seq=")              .append(packet.getSequenceNumber())              .append(" ttl=").append(packet.getTTL()).append(" time=")              .append(rtt).append(" ms");            System.out.println(buffer.toString());          }        });      System.out.println("PING " + hostname + " (" + hostaddr + ") " +                         ping.getRequestDataLength() + "(" +                         ping.getRequestPacketLength() + ") bytes of data).");      final CountDownLatch latch = new CountDownLatch(1);      executor.scheduleAtFixedRate(new Runnable() {          int counter = count;          public void run() {            try {              if(counter > 0) {                ping.sendEchoRequest(address);                if(counter == count)                  latch.countDown();                --counter;              } else                executor.shutdown();            } catch(IOException ioe) {              ioe.printStackTrace();            }          }        }, 0, 1, TimeUnit.SECONDS);      // We wait for first ping to be sent because Windows times out      // with WSAETIMEDOUT if echo request hasn't been sent first.      // POSIX does the right thing and just blocks on the first receive.      // An alternative is to bind the socket first, which should allow a      // receive to be performed frst on Windows.      latch.await();      for(int i = 0; i < count; ++i)        ping.receiveEchoReply();      ping.close();    } catch(Exception e) {      executor.shutdown();      e.printStackTrace();    }  }}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
午夜精品久久久久久久| 亚洲欧美欧美一区二区三区| 色又黄又爽网站www久久| 国产成人一区二区精品非洲| 免费高清在线视频一区·| 午夜欧美视频在线观看| 舔着乳尖日韩一区| 日韩1区2区日韩1区2区| 免费的国产精品| 国产在线麻豆精品观看| 极品少妇xxxx精品少妇| 国产精品白丝jk白祙喷水网站| 97久久精品人人做人人爽| 国产99久久久国产精品 | 欧美三级中文字| 欧美日韩综合在线免费观看| 欧美老女人第四色| 日韩欧美另类在线| 日本一区二区免费在线观看视频| 国产精品视频线看| 伊人夜夜躁av伊人久久| 天堂va蜜桃一区二区三区漫画版| 美女一区二区三区| 国产成人免费网站| 91久久免费观看| 欧美一区二区免费观在线| 26uuu亚洲综合色| 亚洲欧美偷拍另类a∨色屁股| 亚洲国产一区二区在线播放| 久久精品二区亚洲w码| 成人在线一区二区三区| 欧美视频一二三区| 久久久综合九色合综国产精品| 亚洲国产激情av| 日韩一区精品字幕| 成人午夜电影网站| 欧美精品第1页| 国产精品久久久久久久第一福利| 亚洲国产精品精华液网站| 国产综合色视频| 欧美天堂一区二区三区| 久久人人爽人人爽| 舔着乳尖日韩一区| 色爱区综合激月婷婷| 精品福利在线导航| 亚洲18色成人| 99精品久久99久久久久| 精品国一区二区三区| 一二三四社区欧美黄| 国产很黄免费观看久久| 国产亚洲一区二区三区在线观看| 亚洲h在线观看| 大尺度一区二区| 2024国产精品| 日韩av一区二区三区四区| 色屁屁一区二区| 国产精品看片你懂得 | 26uuu久久天堂性欧美| 一区二区在线观看视频在线观看| 激情深爱一区二区| 欧美日韩一级片在线观看| 最好看的中文字幕久久| 国产美女精品一区二区三区| 777奇米四色成人影色区| 一区二区在线免费| av爱爱亚洲一区| 国产精品免费观看视频| 久久99这里只有精品| 91精品国产91综合久久蜜臀| 亚洲卡通欧美制服中文| av中文字幕不卡| 国产精品妹子av| 成人黄色av电影| 中文久久乱码一区二区| 国产精品一级二级三级| 国产视频一区二区三区在线观看| 蜜臀av一区二区| 欧美大片一区二区| 麻豆一区二区三区| 26uuu欧美| 国产91富婆露脸刺激对白| 欧美国产一区视频在线观看| 国产精品系列在线播放| 国产精品视频yy9299一区| 岛国精品一区二区| 一区在线中文字幕| 欧美视频在线一区二区三区| 亚洲一区二区三区四区在线观看| 337p日本欧洲亚洲大胆色噜噜| 免费日韩伦理电影| 日韩亚洲欧美在线| 国产一区不卡视频| 亚洲欧洲三级电影| 在线免费一区三区| 免费成人在线观看视频| 久久久电影一区二区三区| 不卡大黄网站免费看| 亚洲精品日韩一| 9191久久久久久久久久久| 久久电影网站中文字幕| 中文在线免费一区三区高中清不卡| 99久久精品国产导航| 亚洲成a人在线观看| 精品不卡在线视频| 91蝌蚪porny成人天涯| 午夜久久电影网| 久久精品亚洲麻豆av一区二区| 91免费看片在线观看| 日韩精品乱码免费| 国产精品欧美久久久久一区二区| 欧美三级蜜桃2在线观看| 久草在线在线精品观看| 国产精品高潮呻吟久久| 欧美妇女性影城| 风间由美中文字幕在线看视频国产欧美| 亚洲人亚洲人成电影网站色| 欧美一区二视频| 9人人澡人人爽人人精品| 日韩高清不卡在线| 亚洲色图在线看| 欧美r级电影在线观看| 一本大道久久a久久精二百| 美日韩一级片在线观看| 亚洲欧美一区二区三区孕妇| 日韩欧美国产一二三区| 91黄色小视频| 日韩一区二区三区在线观看 | 国产91精品欧美| 日韩在线观看一区二区| 亚洲视频网在线直播| www成人在线观看| 欧美高清视频www夜色资源网| 成人午夜电影久久影院| 精品一区二区三区日韩| 亚洲成va人在线观看| 亚洲人精品一区| 中文字幕色av一区二区三区| 欧美精品一区二区三| 欧美高清dvd| 欧美人与z0zoxxxx视频| 色菇凉天天综合网| 色综合天天综合网天天看片| 国产成人99久久亚洲综合精品| 蜜臀国产一区二区三区在线播放 | 欧美一级午夜免费电影| 欧亚洲嫩模精品一区三区| 国产不卡视频在线播放| 国产一二精品视频| 精品亚洲成a人| 韩日精品视频一区| 国产综合色在线| 国产福利一区在线观看| 国产主播一区二区三区| 久久se这里有精品| 韩国成人在线视频| 国产美女一区二区三区| 国产精品乡下勾搭老头1| 国产精品一区久久久久| 国产精品18久久久久久vr| 国产一区二三区好的| 国产剧情av麻豆香蕉精品| 国产精品小仙女| 97精品视频在线观看自产线路二| caoporm超碰国产精品| 99久久精品免费精品国产| 一本一本久久a久久精品综合麻豆| 99久久精品一区| 欧美日韩国产小视频| 51久久夜色精品国产麻豆| 日韩欧美区一区二| 国产日韩欧美一区二区三区乱码| 中文字幕乱码日本亚洲一区二区 | 亚洲国产日日夜夜| 香蕉av福利精品导航| 美女任你摸久久| 粉嫩av一区二区三区| 色老汉av一区二区三区| 777午夜精品视频在线播放| 精品国产乱码久久久久久久| 中文字幕av一区二区三区高| 亚洲永久免费视频| 久久精品国产精品青草| 国产精品538一区二区在线| 99久久国产综合精品色伊| 欧美日本在线播放| 久久婷婷色综合| 夜夜嗨av一区二区三区四季av| 日本不卡高清视频| 成人午夜又粗又硬又大| 欧美军同video69gay| 久久婷婷成人综合色| 亚洲综合男人的天堂| 激情六月婷婷综合| 欧美色综合影院| 中文无字幕一区二区三区| 午夜激情综合网| 91麻豆精品视频| 国产免费成人在线视频| 亚洲chinese男男1069| av亚洲精华国产精华精|