Conception d'interface graphique pour logiciel de scan de ports
Cet exemple recherche un port sur l'ordinateur
Note: pour lancer la recherche saisir @ ip ou nom de l'ordinateur uniquement, comme dans l'image :
http://img638.imageshack.us/img638/3089/portscanner.png
Et les résultats seront affichés de cette façon :
http://img857.imageshack.us/img857/2449/resultato.png
Code:
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 35 36 37 38 39 40
|
import java.net.*;
import java.io.IOException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PScanner {
public static void main(String[] args) {
InetAddress ia = null;
String host = null;
try {
host = JOptionPane.showInputDialog("Entrer le nom du machine a scanner:\n example: x.x.x.x");
if(host!=null) {
ia = InetAddress.getByName(host); scan(ia);
}
}
catch (UnknownHostException e) {
System.err.println(e );
}
System.out.println("kingslouma");
//System.exit(0);
}
public static void scan(final InetAddress remote) {
//variables for menu bar
int port=0;
String hostname = remote.getHostName();
for ( port = 0; port < 65536; port++) {
try {
Socket s = new Socket(remote,port);
System.out.println("Serveur à l'écoute sur le port " + port+ " de " + hostname);
s.close();
}
catch (IOException ex) {
// The remote host is not listening on this port
System.out.println("Serveur n'est pas a l'écoute sur le port " + port+ " de " + hostname);
}
}
}
} |
je souhaiterai l'afficher de cette façon :
http://img818.imageshack.us/img818/7387/profetionel.png
NB : c'est pour une utilisation sur un réseau local.
Merci d'avance