amine1988
عضو مميز
- إنضم
- 22 جوان 2007
- المشاركات
- 992
- مستوى التفاعل
- 515
Bonjour,
j'ai télécharger un programme du net mon but est de trouvé un code qui permet de faire testes sur des ports d'une machine distante pour savoir s'il sont en écoute ou non en un temp meilleur
voila ce programme il marche très bien me je comprend pas la résultat
merci de me l'expliquer et de me le modifier afin qu'il rependrai a mes besoins
classe Ping
كود:
import java.io.*;
import java.net.*;
import java.nio.channels.*;
public class Ping {
private static int timeout; // Timeout in ms for pinging
private static Target t;
private static SocketChannel sc;
// Representation of a ping target
private static class Target {
public InetSocketAddress address;
public SocketChannel channel;
public long connectStart;
public long connectFinish = 0;
public Exception failure = null;
public Target(String host, int port) throws IOException
{
address = new InetSocketAddress(InetAddress.getByName(host), port);
**
public long getPing() throws IOException, InterruptedException
{
if (connectFinish != 0)
return connectFinish - connectStart;
else if (failure != null)
if (failure instanceof IOException) throw (IOException) failure;
else if (failure instanceof InterruptedException)throw (InterruptedException) failure;
else
return -2; //should not happen
el le main pour tester il faut juste modifier l'adresse ip
كود:
import java.io.IOException;
public class Main
{
public static void main(String[] args) throws InterruptedException, IOException
{
Ping p = null;
System.out.println(p.ping("127.0.0.1", 3306, 4000)); //host,port, timeout in ms
**
**
merci bonne soirée