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
el le main pour tester il faut juste modifier l'adresse ip
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 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
merci bonne soirée
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 package timeout; 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 } }
Partager