-
java 实现 icmp协议测试
2018-11-05 09:42:30java 实现 icmp协议测试 需要在java lib目录下添加libjpcap.so文件 -
利用java实现ICMP协议在linux环境配
2012-05-12 15:52:06利用java实现ICMP协议在linux环境配 -
java icmp ping_纯Java实现ICMP的ping命令
2021-02-26 10:32:34import java.io.*;import java.net.*;import java.nio.channels.*;import java.util.*;import java.util.regex.*;public class Ping {static int DAYTIME_PORT = 13;static int port = DAYTIME_PORT;static class Ta...import java.io.*;
import java.net.*;
import java.nio.channels.*;
import java.util.*;
import java.util.regex.*;
public class Ping {
static int DAYTIME_PORT = 13;
static int port = DAYTIME_PORT;
static class Target {
InetSocketAddress address;
SocketChannel channel;
Exception failure;
long connectStart;
long connectFinish = 0;
boolean shown = false;
Target(String host) {
try {
address = new InetSocketAddress(InetAddress.getByName(host),
port);
} catch (IOException x) {
failure = x;
}
}
void show() {
String result;
if (connectFinish != 0)
result = Long.toString(connectFinish - connectStart) + "ms";
else if (failure != null)
result = failure.toString();
else
result = "Timed out";
System.out.println(address + " : " + result);
shown = true;
}
}
static class Printer extends Thread {
LinkedList pending = new LinkedList();
Printer() {
setName("Printer");
setDaemon(true);
}
void add(Target t) {
synchronized (pending) {
pending.add(t);
pending.notify();
}
}
public void run() {
try {
for (;;) {
Target t = null;
synchronized (pending) {
while (pending.size() == 0)
pending.wait();
t = (Target) pending.removeFirst();
}
t.show();
}
} catch (InterruptedException x) {
return;
}
}
}
static class Connector extends Thread {
Selector sel;
Printer printer;
LinkedList pending = new LinkedList();
Connector(Printer pr) throws IOException {
printer = pr;
sel = Selector.open();
setName("Connector");
}
void add(Target t) {
SocketChannel sc = null;
try {
sc = SocketChannel.open();
sc.configureBlocking(false);
boolean connected = sc.connect(t.address);
t.channel = sc;
t.connectStart = System.currentTimeMillis();
if (connected) {
t.connectFinish = t.connectStart;
sc.close();
printer.add(t);
} else {
synchronized (pending) {
pending.add(t);
}
sel.wakeup();
}
} catch (IOException x) {
if (sc != null) {
try {
sc.close();
} catch (IOException xx) {
}
} t.failure = x;
printer.add(t);
}
}
void processPendingTargets() throws IOException {
synchronized (pending) {
while (pending.size() > 0) {
Target t = (Target) pending.removeFirst();
try {
t.channel.register(sel, SelectionKey.OP_CONNECT, t);
} catch (IOException x) {
t.channel.close();
t.failure = x;
printer.add(t);
}
}
}
}
void processSelectedKeys() throws IOException {
for (Iterator i = sel.selectedKeys().iterator(); i.hasNext();) {
SelectionKey sk = (SelectionKey) i.next();
i.remove();
Target t = (Target) sk.attachment();
SocketChannel sc = (SocketChannel) sk.channel();
try {
if (sc.finishConnect()) {
sk.cancel();
t.connectFinish = System.currentTimeMillis();
sc.close();
printer.add(t);
}
} catch (IOException x) {
sc.close();
t.failure = x;
printer.add(t);
}
}
}
volatile boolean shutdown = false;
void shutdown() {
shutdown = true;
sel.wakeup();
}
public void run() {
for (;;) {
try {
int n = sel.select();
if (n > 0)
processSelectedKeys();
processPendingTargets();
if (shutdown) {
sel.close();
return;
}
} catch (IOException x) {
x.printStackTrace();
}
}
}
}
public static void main(String[] args) throws InterruptedException,
IOException {
args = new String[] { "8888", "192.168.10.193" };
if (args.length < 1) {
System.err.println("Usage: java Ping [port] host...");
return;
}
int firstArg = 0;
if (Pattern.matches("[0-9]+", args[0])) {
port = Integer.parseInt(args[0]);
firstArg = 1;
}
Printer printer = new Printer();
printer.start();
Connector connector = new Connector(printer);
connector.start();
LinkedList targets = new LinkedList();
for (int i = firstArg; i < args.length; i++) {
Target t = new Target(args[i]);
targets.add(t);
connector.add(t);
}
Thread.sleep(2000);
connector.shutdown();
connector.join();
for (Iterator i = targets.iterator(); i.hasNext();) {
Target t = (Target) i.next();
if (!t.shown)
t.show();
}
}
}
纯Java实现ICMP的ping命令.doc
下载Word文档到电脑,方便收藏和打印[全文共2502字]
编辑推荐:
下载Word文档
-
java实现icmp攻击_java使用rocksaw和vserv tcpip实现基于ICMP的Ping功能
2021-03-22 18:11:34java使用rocksaw和vserv tcpip实现基于ICMP的Ping功能一:准备 www.savarese.orgdownload1. rocksaw-1.0.0-src.tar.gz2. vserv-tcpip-0.9.2-src.tar.gz二:编译源文件得到jar包 使用Ant1. build vserv-tcpip-0.9.2-...java使用rocksaw和vserv tcpip实现基于ICMP的Ping功能
一:准备 www.savarese.org download
1. rocksaw-1.0.0-src.tar.gz
2. vserv-tcpip-0.9.2-src.tar.gz
二:编译源文件得到jar包 使用Ant
1. build vserv-tcpip-0.9.2-src
在vserv-tcpip-0.9.2目录下面建一个tests目录,然后在cmd窗口下进入vserv-tcpip-0.9.2-src目录,执行Ant all命令,相关的API、 class、jar包都生成好了,jar包在lib目录下
2. build rocksaw-1.0.0-src
ant all
错误原因:jdk version低于1.5
错误原因:build.properties 默认是使用linux/unix操作系统上的gcc和gmake
jni.make=gmake
jni.cc=gcc
解决:
#nmake工具去微软官网下一个修复版本nmake15.exe,运行 将NMAKE.EXE放到system32目录下
jni.make=nmake
#安装C++工具包 Microsoft Visual C++ Toolkit 2003,将bin、inlude、lib加入环境变量path中,这样就可以直接使用cl命令编译
jni.cc=cl
错误原因:jni.makefile=Makefile 这是linux/unix上的makefile
解决:jni.makefile=Makefile.win32 文件在\rocksaw-1.0.0\src\jni下
错误原因:可能是没有找到jdk目录下的include目录,erron.h是Microsoft Visual C++ Toolkit 2003\include下的
解决方法:将java环境变量JAVA_HOME改为JDK_HOME或者在Makefile.win32中直接修改 JAVA_INCDIR=$(JAVA_HOME)\include,然后将Microsoft Visual C++ Toolkit 2003\include下的erron.h拷贝到jdk\include下
错误原因:没有找到string.h
解决方法:在Makefile.win32中添加两个变量(CPP_HOME : Microsoft Platform SDK)
 
相关文档:
Java学习从入门到精通
一、 JDK (Java Development Kit)
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......
在应用开发中,经常需要一些周期性的操作,比如每5分钟执行某一操作等。在WEB项目中可能需要每隔一段时间自动生成静态页,自动检测是否有新邮件,定时自动备份文件等操作。这些都可以通过定时器Timer来解决。
这里仅提供定时器的部分方法和说明,静态页生成等操作读者可以通过相关方法自行解决。
。。。百度空间贴代码总� ......
在处理监测数据实时录入时,需要提供当前班次信息{大白班,小夜班,大夜班},班次信息是根据给定时间段进行设定类似{{"8:00","16:00"},{"16:00","00:00"},{"00:00","8:00"}}
处理办法
· 取当前时间、转换验证起始、结束时间进行比较。
相关代码
/**
* 时间段测试
......
1、JDK (Java Development Kit)
SUN的Java不仅提了一个丰富的语言和运行环境,而且还提了一个免费的Java开发工具集(JDK)。开发人员和最终用户可以利用这个工具来开发java程序。
JDK简单易学,可以通过任何文本编辑器(如:Windows 记事本、UltrEdit、Editplus、FrontPage以及dreamweaver等)编写Java源文件,然 ......
霍纳规则多项式计算如果使用朴素的多项式求值,时间复杂度为O(n*n),而是用了霍纳规则可以使用递归或者迭代来实现,时间复杂度是O(n),下面是源代码:
/*
* 实现霍纳规则的多项式计算时间复杂度为O(N)
*/
public class HuonaRule {
public static void main(String args[])
{
double data[]=new double[]{1.0,2, ......
-
java ping 实现的_纯java实现ICMP的ping命令
2021-02-12 14:23:32importjava.io.*;importjava.net.*;importjava.nio.channels.*;importjava.util.*;importjava.util.regex.*;publicclassPing {staticintDAYTIME_PORT=13;staticintport=DAYTIME_PORT;staticclassTarget {InetSocketA...importjava.io.*;importjava.net.*;importjava.nio.channels.*;importjava.util.*;importjava.util.regex.*;publicclassPing {staticintDAYTIME_PORT=13;staticintport=DAYTIME_PORT;staticclassTarget {
InetSocketAddress address;
SocketChannel channel;
Exception failure;longconnectStart;longconnectFinish=0;booleanshown=false;
Target(String host) {try{
address=newInetSocketAddress(InetAddress.getByName(host),
port);
}catch(IOException x) {
failure=x;
}
}voidshow() {
String result;if(connectFinish!=0)
result=Long.toString(connectFinish-connectStart)+"ms";elseif(failure!=null)
result=failure.toString();elseresult="Timed out";
System.out.println(address+":"+result);
shown=true;
}
}staticclassPrinterextendsThread {
LinkedList pending=newLinkedList();
Printer() {
setName("Printer");
setDaemon(true);
}voidadd(Target t) {synchronized(pending) {
pending.add(t);
pending.notify();
}
}publicvoidrun() {try{for(;;) {
Target t=null;synchronized(pending) {while(pending.size()==0)
pending.wait();
t=(Target) pending.removeFirst();
}
t.show();
}
}catch(InterruptedException x) {return;
}
}
}staticclassConnectorextendsThread {
Selector sel;
Printer printer;
LinkedList pending=newLinkedList();
Connector(Printer pr)throwsIOException {
printer=pr;
sel=Selector.open();
setName("Connector");
}voidadd(Target t) {
SocketChannel sc=null;try{
sc=SocketChannel.open();
sc.configureBlocking(false);booleanconnected=sc.connect(t.address);
t.channel=sc;
t.connectStart=System.currentTimeMillis();if(connected) {
t.connectFinish=t.connectStart;
sc.close();
printer.add(t);
}else{synchronized(pending) {
pending.add(t);
}
sel.wakeup();
}
}catch(IOException x) {if(sc!=null) {try{
sc.close();
}catch(IOException xx) {
}
}
t.failure=x;
printer.add(t);
}
}voidprocessPendingTargets()throwsIOException {synchronized(pending) {while(pending.size()>0) {
Target t=(Target) pending.removeFirst();try{
t.channel.register(sel, SelectionKey.OP_CONNECT, t);
}catch(IOException x) {
t.channel.close();
t.failure=x;
printer.add(t);
}
}
}
}voidprocessSelectedKeys()throwsIOException {for(Iterator i=sel.selectedKeys().iterator(); i.hasNext();) {
SelectionKey sk=(SelectionKey) i.next();
i.remove();
Target t=(Target) sk.attachment();
SocketChannel sc=(SocketChannel) sk.channel();try{if(sc.finishConnect()) {
sk.cancel();
t.connectFinish=System.currentTimeMillis();
sc.close();
printer.add(t);
}
}catch(IOException x) {
sc.close();
t.failure=x;
printer.add(t);
}
}
}volatilebooleanshutdown=false;voidshutdown() {
shutdown=true;
sel.wakeup();
}publicvoidrun() {for(;;) {try{intn=sel.select();if(n>0)
processSelectedKeys();
processPendingTargets();if(shutdown) {
sel.close();return;
}
}catch(IOException x) {
x.printStackTrace();
}
}
}
}publicstaticvoidmain(String[] args)throwsInterruptedException,
IOException {
args=newString[] {"8888","192.168.10.193"};if(args.length<1) {
System.err.println("Usage: java Ping [port] host...");return;
}intfirstArg=0;if(Pattern.matches("[0-9]+", args[0])) {
port=Integer.parseInt(args[0]);
firstArg=1;
}
Printer printer=newPrinter();
printer.start();
Connector connector=newConnector(printer);
connector.start();
LinkedList targets=newLinkedList();for(inti=firstArg; i
Target t=newTarget(args[i]);
targets.add(t);
connector.add(t);
}
Thread.sleep(2000);
connector.shutdown();
connector.join();for(Iterator i=targets.iterator(); i.hasNext();) {
Target t=(Target) i.next();if(!t.shown)
t.show();
}
}
}
-
java实现ICMP协议的ping功能
2017-08-29 15:45:11package com.beijia.test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.UnknownHostException; import java.utpackage com.beijia.test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Ping { public static boolean ping(String ipAddress) throws Exception{ int timeOut=3000; boolean status=InetAddress.getByName(ipAddress).isReachable(timeOut); // 当返回值是true时,说明host是可用的 return status; } public static void ping02(String ipAddress){ String line=null; try { Process pro=Runtime.getRuntime().exec("ping "+ipAddress); BufferedReader buf=new BufferedReader(new InputStreamReader(pro.getInputStream())); while((line=buf.readLine())!=null){ System.out.println(line); } } catch (Exception e) { System.out.println(e.getMessage()); } } public static boolean ping(String ipAddress,int pingTimes,int timeOut){ BufferedReader in=null; Runtime r=Runtime.getRuntime(); String pingCommand="ping "+ipAddress+" -n "+pingTimes+" -w "+timeOut; try {//执行命令并获取输出 System.out.println(pingCommand); Process p=r.exec(pingCommand); if(p==null){ return false; } in=new BufferedReader(new InputStreamReader(p.getInputStream())); int connectedCount=0; String line=null; while((line=in.readLine())!=null){ connectedCount+=getCheckResult(line); }//如果出现类似=20ms TTL=22这样的字符,出现的次数=测试次数 则返回真 return connectedCount==pingTimes; } catch (Exception e) { e.printStackTrace();//出现异常则返回假 return false; }finally{ try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } //若line含有=18ms TTL=16字样,说明已经ping通,返回1,否則返回0. private static int getCheckResult(String line){ Pattern pattern=Pattern.compile("(\\d+ms)(\\s+)(TTL=\\d+)",Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(line); while(matcher.find()){ return 1; } return 0; } public static void main(String[] args) throws Exception{ String ipAddress="192.168.20.58"; System.out.println(ping(ipAddress)); ping02(ipAddress); System.out.println(ping(ipAddress,5,5000)); } }
-
java 开源icmp ping_icmp的程序(ping的实现)
2021-03-16 15:43:06code来源于《网络编程与分层协议设计》 chap7 ICMP协议程序设计----没有理解,没有编译,只是敲了出来ping.h#define ICMP_ECHOREPLY 0#define ICMP_ECHO 8#define BUFSIZE 1500#define DEFAULT_LEN 56typedef ... -
java_icmp_ping
2018-11-26 21:08:36使用Java语言开发 基于ICMP协议 仿Windows系统的Ping程序 简单实现 使用了Jpcap 计算机网络课程设计的作业 -
基于java实现ping_java实现ping功能
2021-02-27 18:41:45一、纯Java实现ICMP的ping命令import java.io.*;import java.net.*;import java.nio.channels.*;import java.util.*;import java.util.regex.*;public class Ping {static int DAYTIME_PORT = 13;static int port = ... -
java ping 实现的_java实现ping功能
2021-02-12 14:23:32一、纯Java实现ICMP的ping命令import java.io.*;import java.net.*;import java.nio.channels.*;import java.util.*;import java.util.regex.*;public class Ping {static intDAYTIME_PORT = 13;static intport = ... -
java ping 包_Java实现Ping功能和发送ICMP数据包
2021-02-26 10:07:30import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.net.InetAddress;import java.net.UnknownHostException;public class SendICMPUtil {/*** @param host*/... -
用java实现ping的几种方式
2012-12-02 17:31:44用java实现ping的几种方式:纯Java实现ICMP的ping命令,JAVA调用外部EXE实现PING功能,ICMP Ping in Java(JDK 1.5 and above),最简单的办法,直接调用CMD -
java实现ping功能
2018-05-29 13:13:00转载 自 ... 一、纯Java实现ICMP的ping命令 import java.io.*; import java.net.*; import java.nio.channels.*; import java.util.*; import java.util.regex.... -
从0到1用java再造tcpip协议栈:使用责任链模式实现ICMP错误数据报解析
2018-12-28 07:26:57同时我们详细解析了包含错误消息时的数据格式,本节我们使用代码来实现ICMP错误数据报的解析。 上图显示的是ICMP数据报包含错误消息时的格式。它一个特点是底层数据格式需要根据上头type和code两个字段指定,这两个... -
java 实现ping
2012-03-29 09:52:00一、纯Java实现ICMP的ping命令import java.io.*;import java.net.*;import java.nio.channels.*;import java.util.*;import java.util.regex.*;public class Ping { static int DAYTIME_PORT = 13; static int ... -
Java 实现Ping功能
2013-02-25 16:56:19一、纯Java实现ICMP的ping命令 import java.io.*; import java.net.*; import java.nio.channels.*; import java.util.*; import java.util.regex.*; public class Ping { static int DAYTIME_PORT = 13; ... -
java代码实现ping
2019-02-22 14:58:24一、纯Java实现ICMP的ping命令 import java.io.*; import java.net.*; import java.nio.channels.*; import java.util.*; import java.util.regex.*; public class Ping { static int DAYTIME_PORT = 13; ... -
java实现ping功能的几种方法
2016-01-22 17:20:15一、纯Java实现ICMP的ping命令 import java.io.*; import java.net.*; import java.nio.channels.*; import java.util.*; import java.util.regex.*; public class Ping { static intDAYTIME_POR -
Java实现Ping功能
2010-08-29 18:41:59转载自:tswang的博客,地址:... 一、纯Java实现ICMP的ping命令 import java.io.*; import java.net.*; import java.nio.channels.*; import java.util.*; impo... -
icmp java_如何在Java中使用ICMP和traceroutes
2021-02-27 15:11:27这就是我今天在Java中“实现”trace route命令所写的内容.我只在Windows中进行了测试,但它也应该在Linux中运行,尽管有几种可用于Linux的traceroute工具,因此很可能需要对这些程序的存在进行一些检查.public class ... -
java实现ping计算机网络_计算机网络课程设计-----基于ICMP的PING设计.doc
2021-03-11 11:12:54计算机网络课程设计-----基于ICMP的PING设计编程实现基于ICMP的PING学生姓名: 指导老师:摘 要 本次课程设计主要是基于Linux系统,使用编程语言C语言,编写一个实验程序,实现基于ICMP报文的PING的类似功能。... -
java 实现的 ping程序
2011-06-14 16:54:25由java实现的icmp报文的ping程序 -
从0到1用java再造tcpip协议栈:ICMP协议的原理和实现
2018-12-22 17:18:45绝大多数TCPIP传输协议基于IP寻址协议,然后建造在IP之上的TCP和UDP两种协议用于控制数据包的传输。问题在于这些协议只关注数据传输,在传输过程中如果出现错误信息,或者是...ICMP协议在保证数据的准确发送上发挥了... -
icmp协议 主机探测 java 网盘_ICMP协议 广播以查询局域网内的所有主机
2021-03-01 09:17:58看到了很多局域网内的主机扫描工具,在想怎么去实现这样一个工具。前几天看了Ping源码--ICMP协议的实例,ICMP可以用来探测网联网内的任一主机,ICMP和广播地址结合来扫描局域网内的所有主机不是很容易吗。... -
java实现ip分片_速读原著-TCP/IP(ICMP不可达差错(需要分片))
2021-03-22 18:12:30第11章 UDP:用户数据报协议11.6 ICMP不可达差错(需要分片)发生I C M P不可达差错的另一种情况是,当路由器收到一份需要分片的数据报,而在 I P首部又设置了不分片(D F)的标志比特。如果某个程序需要判断到达目的端...