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);
}
}
}
} |
Partager