⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ping.java

📁 这是ICMP源程序包含PING的接收和发送
💻 JAVA
字号:
import java.util.*;import java.math.*;public class Ping {    private native int icmp_send(String host, int sequence, String data);    private native String icmp_recv(int timeout);    static {	System.loadLibrary("ping");    }    private int counter;    private HashSet received;    public Ping() {	counter = 0;	received = new HashSet();    }    public int send(String host) {	return send(host, "012345678901234567890123456789");    }    public int send(String host, int bytes) {	StringBuffer sb = new StringBuffer();	for (int i = 0; i < bytes; i++) {	    sb.append(i%9);	}	return send(host, sb.toString());    }    public int send(String host, String data) {	if (data.length() > 64000) {	    System.err.println("Data item too long. 64,000 bytes max.");	    return -5;	}	data = System.currentTimeMillis() + " " + data;	int ret = icmp_send(host, counter, data);	counter++;	return ret;    }    public long recv(int timeout) {	String res = icmp_recv(timeout);		long endtime = System.currentTimeMillis();		boolean duplicate = false;	if (res == null) {	    System.err.println("Timeout waiting for packet");	    return -1;	}		Integer I = new Integer(res.substring(0, res.indexOf(" ")));	if (received.contains(I)) {	    duplicate = true;	} else {	    received.add(I);	}	String data = res.substring((res.indexOf(" ")+1));	data = data.substring(0, data.indexOf(" "));	BigInteger bi =	new BigInteger(data);	long starttime = bi.longValue();	return (endtime - starttime);    }}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -