| 12
 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
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 
 | import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
 
 
public class PortScanner extends JFrame{
 
	Socket s;
	int startPort,endPort;
	Label l1;
	TextField hostName,fromPort,toPort;
	TextArea log;
	Label host,from,to,label;
	Button scan,reset;
	int fp,tp;
	String h;
	static boolean close=false;
	Dialog d;
 
	JFrame f=new JFrame("Port Scanner");
 
 
	public PortScanner(){
 
		l1=new Label("Port Scanner",Label.CENTER);
		l1.setForeground(Color.red);
		l1.setFont(new Font("TimesRoman",Font.BOLD,25));
		f.add(l1);
 
		Panel p1=new Panel(new GridLayout(3,3));
		host=new Label("Adresse IP :");
		host.setForeground(Color.blue);
		host.setFont(new Font("TimesRoman",Font.BOLD,15));
		p1.add(host);
 
		hostName=new TextField(15);
		p1.add(hostName);
 
		from=new Label("Port Début:");
		from.setForeground(Color.blue);
		from.setFont(new Font("TimesRoman",Font.BOLD,15));
		p1.add(from);
		fromPort=new TextField(15);
		p1.add(fromPort);
 
		to=new Label("Port Fin:");
		to.setForeground(Color.blue);
		to.setFont(new Font("TimesRoman",Font.BOLD,15));
		p1.add(to);
		toPort=new TextField(15);
		p1.add(toPort);
		f.add(p1);
 
		Panel p2=new Panel();
		scan=new Button("Scan");
		scan.addActionListener(new ActionListener(){
 
			public void actionPerformed(ActionEvent r){
					if(hostName.getText().equals("")){
							JOptionPane.showMessageDialog(null, "VEUILLEZ REMPLIR TOUS LES CHAMPS");
							return;}
					else if (fromPort.getText().equals("")){
							JOptionPane.showMessageDialog(null, "VEUILLEZ REMPLIR TOUS LES CHAMPS");
							return;}
					else if(toPort.getText().equals("")){
							JOptionPane.showMessageDialog(null, "VEUILLEZ REMPLIR TOUS LES CHAMPS");
							return;}		
					close=false;
					Thread run1=new Thread(){
 
						public void run(){
							scan.setEnabled(false);
							reset.setLabel("Stop");
							log.setText("");
							log.repaint();
 
							h=hostName.getText();
							fp=Integer.parseInt(fromPort.getText());
							tp=Integer.parseInt(toPort.getText());
 
							for(int i=fp;i<=tp;i++){
								label.setText("Port "+i+" en cour de test...");
								if(close)
									break;
								try{
									s=new Socket(h,i);
									log.append("Port "+i+" est ouvert."+"\n");
									log.repaint();
									s.close();
									}
								catch(Exception er){
									continue;}
							}
 
							scan.setEnabled(true);
							reset.setLabel("Reset");
							label.setText("Press Scan to start.");
						}
					};
					run1.start();
			}
		});
 
		reset=new Button("Reset");
		reset.addActionListener(new ActionListener(){
 
			public void actionPerformed(ActionEvent t){
				Thread run2=new Thread(){
					public void run(){
						close=true;
						hostName.setText("");
						fromPort.setText("");
						toPort.setText("");
					}
				};
				run2.start();
			}
		});
 
		Label empty=new Label();
		p2.add(scan);
		p2.add(empty);
		p2.add(reset);
		f.add(p2);
 
		log=new TextArea();
		f.add(log);
 
		label=new Label("Cliquez sur Scan.");
		label.setForeground(Color.blue);
		f.add(label);
 
		f.repaint();
		f.setResizable(false);
 
		f.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(1);
			}
		});
 
 
		f.setBackground(Color.LIGHT_GRAY);
		f.pack();
		f.setVisible(true);
		f.setSize( 320,500);
		f.setLocationRelativeTo(null);
		f.setLayout(new GridLayout(5,1));
 
		JMenuBar barre = new JMenuBar();
		JMenu fichier = new JMenu("Fichier");
		JMenu edition = new JMenu("Edition");
		JMenu aide = new JMenu("Aide");
 
		JMenuItem enregistrer = new JMenuItem("Enregistrer sous...");
		JMenuItem quitter = new JMenuItem("Quitter");
		JMenuItem couper = new JMenuItem("Couper");
		JMenuItem copier = new JMenuItem("Copier");
		JMenuItem coller = new JMenuItem("Coller");
		JMenuItem about = new JMenuItem("About");
 
		barre.add(fichier);
		barre.add(edition);
		barre.add(aide);
 
		fichier.add(enregistrer);
		fichier.add(quitter);
 
		edition.add(couper);
		edition.add(copier);
		edition.add(coller);
 
		aide.add(about);
 
		f.setJMenuBar(barre);
 
		quitter.addActionListener(new ActionListener() {
		         public void actionPerformed(ActionEvent e) {
		            System.exit(0);
		         }
		 });
 
	}
 
 
 
	public static void main(String args[]){
 
		new PortScanner();
 
	}
 
} | 
Partager