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:
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:
|
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.Socket;
public class Main extends JFrame
{
private static final long serialVersionUID = 1L;
private JButton scan;
private JTextField port_von;
private JTextField port_bis;
private JTextArea ergebniss;
private JPanel panel;
private JLabel oben;
boolean scan_now = false;
Socket verbindung;
int scan_port_von;
int scan_port_bis;
int i;
String ergebniss_cache;
public Main()
{
super("GUI-Portscanner");
setLocation(0,0);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout(5,5));
scan = new JButton("Beginnen");
port_von = new JTextField("80");
port_bis = new JTextField("81");
ergebniss = new JTextArea("", 1, 5);
panel = new JPanel(new GridLayout(3,1));
panel.add(scan);
panel.add(port_von);
panel.add(port_bis);
panel.add(ergebniss);
addButtonListener(scan);
oben = new JLabel("GUI-Portscan");
oben.setHorizontalAlignment(JLabel.CENTER);
getContentPane().add(BorderLayout.NORTH, oben);
getContentPane().add(BorderLayout.WEST, panel);
pack();
setVisible(true);
}
public static void main(String[] args) throws IOException
{
Main g = new Main();
}
private void addButtonListener(JButton b)
{
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
if(scan_now == false)
{
scan_now = true;
scan_port_von = Integer.parseInt(port_von.getText());
scan_port_bis = Integer.parseInt(port_bis.getText());
ergebniss.setText("");
for(i = Integer.parseInt(port_von.getText()); i <= Integer.parseInt(port_bis.getText()); i++)
{
try
{
verbindung = new Socket("127.0.0.1", i);
ergebniss.setText(ergebniss.getText() + i + " - (halb)offen" + "\n");
}
catch(IOException e)
{
ergebniss.setText(ergebniss.getText() + i + " - geschlossen" + "\n");
}
}
}
else
{
scan_now = false;
}
}
});
}
} |