多线程实现端口扫描

  1 import java.net.*;
  2 import java.io.*;
  3 import java.awt.*;
  4 import java.awt.event.*;
  5 import javax.swing.*;
  6
  7 public class TcpThread extends Thread{
  8
  9     //定义变量
 10     public static InetAddress hostAddress;//主机IP地址
 11     public static int MIN_port;            //The minimal number of port
 12     public static int MAX_port;            //The maximal number of port
 13     private int NUM_thread;                //线程总数
 14     public static int type;                //查询方式,0为IP方式1为主机名查询方式
 15
 16     public static int ip1;//IP前三位
 17     public static int ip2;//IP4~6位
 18     public static int ip3;//IP7~9位
 19     public static int ipstart;//起始IP地址最后四位
 20     public static int ipend;//结束IP地址最后四位
 21     public static String ipAll;//完整的IP地址
 22
 23     String nameHost = "";//扫描的主机名称或IP地址
 24     String typeport = "0";//端口类别
 25
 26     /**
 27      * 构造函数
 28      */
 29     public TcpThread( String name, int numthread ){
 30         super(name);
 31         this.NUM_thread = numthread;
 32     }
 33
 34     /**
 35      * run()运行函数
 36      */
 37     public void run( ) {
 38
 39         int h = 0;//IP address
 40         int i = 0;//port number
 41
 42         Socket theTcpSocket;
 43
 44         //根据IP地址进行扫描
 45         if( 0 == type ){
 46             //IP地址循环扫描
 47             for( h = ipstart; h <= ipend; h++){
 48                 ipAll = "" + ip1 + "." + ip2 + "." + ip3 + "." + h;
 49                 nameHost = ipAll;
 50
 51                 try{
 52                     hostAddress = InetAddress.getByName( ipAll );
 53                 }catch( UnknownHostException e){}
 54
 55                 //不同端口循环扫描
 56                 for( i = MIN_port; i < MAX_port + Integer.parseInt( ThreadScan.maxThread.getText() );
 57                         i += Integer.parseInt(ThreadScan.maxThread.getText() ) ){
 58                     try{
 59                         theTcpSocket = new Socket(hostAddress, i);
 60                         theTcpSocket.close();
 61
 62                         ThreadScan.Result.append( nameHost +":"+i);
 63
 64                         switch( i ){//其实这儿可以不用switch,直接用个hash表记录就可以
 65                             case 21:
 66                                 typeport = "(FTP)";
 67                                 break;
 68                             case 23:
 69                                 typeport = "(TELNET)";
 70                                 break;
 71                             case 25:
 72                                 typeport = "SMTP";
 73                                 break;
 74                             case 80:
 75                                 typeport = "HTTP";
 76                                 break;
 77                             case 110:
 78                                 typeport = "POP";
 79                                 break;
 80                             case 139:
 81                                 typeport = "netBIOS";
 82                                 break;
 83                             case 1433:
 84                                 typeport = "SQL Server";
 85                                 break;
 86                             case 3389:
 87                                 typeport = "Terminal Service";
 88                                 break;
 89                             case 443:
 90                                 typeport = "HTTPS";
 91                                 break;
 92                             case 1521:
 93                                 typeport = "Oracle";
 94                                 break;
 95                         }
 96
 97                         //端口没有特定类型
 98                         if( typeport.equals("0")){
 99                             ThreadScan.Result.append("\n");
100                         }else{
101                             ThreadScan.Result.append(":" + typeport + "\n");
102                         }
103                     }catch( IOException e){}
104                 }
105             }
106             if( i == MAX_port + Integer.parseInt(ThreadScan.maxThread.getText())){
107                 ThreadScan.Result.append("\n" + "扫描完成...");
108                 //请"确定"按钮设置为可用
109                 if( !ThreadScan.Submit.setEnable( true ) );
110             }
111         }
112
113         //按主机名进行端口扫描
114         if( 1 == type ){
115             for( i = MIN_port + NUM_thread; i < MAX_port + Integer.parseInt(ThreadScan.maxThread.getText());
116                     i += Integer.parseInt( ThreadScan.maxThread.getText( ) ) ) {
117                 try{
118                     theTcpSocket = new Socket( hostAddress, i );
119                     theTcpSocket.close();
120                     ThreadScan.Result.append(" " + i);
121                     switch( i ){//其实这儿可以不用switch,直接用个hash表记录就可以
122                         case 21:
123                             typeport = "(FTP)";
124                             break;
125                         case 23:
126                             typeport = "(TELNET)";
127                             break;
128                         case 25:
129                             typeport = "SMTP";
130                             break;
131                         case 80:
132                             typeport = "HTTP";
133                             break;
134                         case 110:
135                             typeport = "POP";
136                             break;
137                         case 139:
138                             typeport = "netBIOS";
139                             break;
140                         case 1433:
141                             typeport = "SQL Server";
142                             break;
143                         case 3389:
144                             typeport = "Terminal Service";
145                             break;
146                         case 443:
147                             typeport = "HTTPS";
148                             break;
149                         case 1521:
150                             typeport = "Oracle";
151                             break;
152                     }
153                     if( typeport.equals("0") ){
154                         ThreadScan.Result.append("\n");
155                     }else{
156                         ThreadScan.Result.append(":" + typeport + "\n");
157                     }
158                 }catch( IOException e){
159
160                 }
161             }
162             if( i == MAX_port + Integer.parseInt(ThreadScan.maxThread.getText())){
163                 ThreadScan.Result.append("\n" + "扫描完成...");
164                 if( !ThreadScan.Submit.isEnable()){
165                     ThreadScan.Submit.setEnabled( true );
166                 }
167             }
168         }//End of if
169     }
170 }
  1 import java.net.*;
  2 import java.io.*;
  3 import java.awt.*;
  4 import java.awt.event.*;
  5 import javax.swing.*;
  6 /**
  7  * 实现扫描的主体程序,TreadScan
  8  * @author Administrator
  9  *
 10  */
 11
 12 public class ThreadScan {
 13
 14     public static JFrame main = new JFrame("Scaner(V1.0)By Nevermore");    //注册框架类
 15     public static JTextArea Result = new JTextArea("", 4, 40);            //显示扫描结果
 16     public static JScrollPane resultPane = new
 17             JScrollPane( Result, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
 18             JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
 19
 20
 21     public static JTextField nameHost = new JTextField("localhost", 8 );//输入主机名文本框
 22     public static JTextField fromip1 = new JTextField("0", 3);            //输入IP地址前三位的文本框
 23     public static JTextField fromip2 = new JTextField("0", 3);            //输入IP地址4~6位的文本框
 24     public static JTextField fromip3 = new JTextField("0", 3);            //输入IP地址7~9位的文本框
 25     public static JTextField fromip4 = new JTextField("0", 3);            //输入IP地址后三位的文本框
 26
 27     public static JTextField toip = new JTextField("0", 3);                //输入目标IP地址后四位
 28
 29     public static JTextField minPort = new JTextField("0", 4);            //最小端口输入框
 30     public static JTextField maxPort = new JTextField("1000", 4);        //最大端口输入框
 31
 32     public static JTextField maxThread = new JTextField("100", 3);        //最大线程数
 33     public static JDialog DLGError = new JDialog(main, "错误!");        //错误提示框
 34     public static JLabel DLGINFO = new JLabel("");
 35     public static JLabel type = new JLabel("请选择:");
 36     //扫描类型
 37     public static JRadioButton radioIP = new JRadioButton("IP地址:");
 38     public static JRadioButton radioHost = new JRadioButton("主机名:", true);
 39     //单选按钮组
 40     public static ButtonGroup group= new ButtonGroup();
 41     public static JLabel p1 = new JLabel("端口范围:");
 42     public static JLabel p2 = new JLabel("~");
 43     public static JLabel p3 = new JLabel("~");
 44     public static JLabel Pdot1 = new JLabel(".");
 45     public static JLabel Pdot2 = new JLabel(".");
 46     public static JLabel Pdot3 = new JLabel(".");
 47     public static JLabel TNUM = new JLabel("线程数:");
 48     public static JLabel RST = new JLabel("扫描结果:");
 49     public static JLabel con = new JLabel("");
 50     //定义按钮
 51     public static JButton Ok = new JButton("确定");
 52     public static JButton Submit = new JButton("开始扫描");
 53     public static JButton Cancel = new JButton("退出");
 54     public static JButton saveButton = new JButton("保存扫描结果");
 55     //菜单栏设计:这一块好好学习学习
 56     public static JMenuBar myBar = new JMenuBar();
 57     public static JMenu myMenu = new JMenu("文件(F)");
 58     public static JMenuItem saveItem = new JMenuItem("保存扫描结果(S)");
 59     public static JMenuItem exitItem = new JMenuItem("退出(Q)");
 60     public static JMenu myMenu2 = new JMenu("帮助");
 61     public static JMenuItem helpItem = new JMenuItem("阅读");
 62
 63     /**
 64      * 主方法
 65      */
 66     public static void main( String[] argcs ){
 67         main.setSize(500, 400);
 68         main.setLocation(400, 400);
 69         main.setResizable(false);
 70         main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 71
 72         DLGError.setSize(300, 100);
 73         DLGError.setLocation(400, 400);
 74         //添加"菜单栏"
 75         myMenu.add(saveItem);
 76         myMenu.add(exitItem);
 77
 78         myMenu2.add(helpItem);
 79
 80         myBar.add(myMenu);//将菜单条目添加到菜单
 81         myBar.add(myMenu2);
 82
 83         main.setJMenuBar(myBar);//将菜单添加到框架
 84         //设置热键
 85         myMenu.setMnemonic(‘F‘);
 86         saveItem.setMnemonic(‘S‘);
 87         //为"另存为"组建设置快捷键CTRL + S
 88         saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
 89         //采用表格包模式布局
 90         Container mPanel = main.getContentPane();
 91         GridBagConstraints c = new GridBagConstraints();
 92         c.insets = new Insets(10, 0, 0, 10);
 93
 94         c.gridx = 0;// 设置表格坐标
 95         c.gridy = 0;
 96         c.gridwidth = 10;
 97         c.fill = GridBagConstraints.BOTH;
 98         c.anchor = GridBagConstraints.CENTER;
 99         mPanel.add(type, c);
100
101         group.add(radioIP);
102         group.add(radioHost);
103
104         c.gridx = 0;
105         c.gridy = 1;
106         c.gridwidth = 1;
107         c.fill = GridBagConstraints.BOTH;
108         c.anchor = GridBagConstraints.CENTER;
109         mPanel.add(radioIP, c);
110
111         c.gridx = 1;
112         c.gridy = 1;
113         c.gridwidth = 1;
114         c.fill = GridBagConstraints.CENTER;
115         mPanel.add(fromip1, c);
116
117         c.gridx = 2;
118         c.gridy = 1;
119         c.gridwidth = 1;
120         c.fill = GridBagConstraints.BOTH;
121         mPanel.add(Pdot1, c);
122
123         c.gridx = 3;
124         c.gridy = 1;
125         c.gridwidth = 1;
126         c.fill = GridBagConstraints.BOTH;
127         c.anchor = GridBagConstraints.CENTER;
128         mPanel.add(fromip2, c);
129
130         c.gridx = 4;
131         c.gridy = 1;
132         c.gridwidth = 1;
133         c.fill = GridBagConstraints.BOTH;
134         c.anchor = GridBagConstraints.CENTER;
135         mPanel.add(Pdot2, c);
136
137         c.gridx = 5;
138         c.gridy = 1;
139         c.gridwidth = 1;
140         c.fill = GridBagConstraints.BOTH;
141         c.anchor = GridBagConstraints.CENTER;
142         mPanel.add(fromip3, c);
143
144         c.gridy = 1;
145         c.gridx = 6;
146         c.gridwidth = 1;
147         c.fill = GridBagConstraints.BOTH;
148         c.anchor = GridBagConstraints.CENTER;
149         mPanel.add(Pdot3, c);
150
151
152         c.gridx = 7;
153         c.gridy = 1;
154         c.gridwidth = 1;
155         c.fill = GridBagConstraints.BOTH;
156         c.anchor = GridBagConstraints.CENTER;
157         mPanel.add(fromip4, c);
158
159         c.gridx = 8;
160         c.gridy = 1;
161         c.gridwidth = 1;
162         c.fill = GridBagConstraints.BOTH;
163         c.anchor = GridBagConstraints.CENTER;
164         mPanel.add(p2, c);
165
166         c.gridx = 9;
167         c.gridy = 1;
168         c.gridwidth = 1;
169         c.fill = GridBagConstraints.BOTH;
170         c.anchor = GridBagConstraints.CENTER;
171         mPanel.add(toip, c);
172
173         c.gridx = 0;
174         c.gridy = 2;
175         c.gridwidth = 1;
176         c.fill = GridBagConstraints.BOTH;
177         c.anchor = GridBagConstraints.CENTER;
178         mPanel.add(radioHost, c);
179
180         c.gridx = 1;
181         c.gridy = 2;
182         c.gridwidth = 3;
183         c.fill = GridBagConstraints.BOTH;
184         c.anchor = GridBagConstraints.CENTER;
185         mPanel.add(nameHost, c);
186
187         c.gridx = 0;
188         c.gridy = 3;
189         c.gridwidth = 1;
190         c.fill = GridBagConstraints.BOTH;
191         c.anchor = GridBagConstraints.CENTER;
192         mPanel.add(p1, c);
193
194         c.gridx = 1;
195         c.gridy = 3;
196         c.gridwidth = 1;
197         c.fill = GridBagConstraints.BOTH;
198         c.anchor = GridBagConstraints.CENTER;
199         mPanel.add(minPort, c);
200
201         c.gridx = 2;
202         c.gridy = 3;
203         c.gridwidth = 1;
204         c.fill = GridBagConstraints.BOTH;
205         c.anchor = GridBagConstraints.CENTER;
206         mPanel.add(p3, c);
207
208         c.gridx = 3;
209         c.gridy = 3;
210         c.gridwidth = 1;
211         c.fill = GridBagConstraints.BOTH;
212         c.anchor = GridBagConstraints.CENTER;
213         mPanel.add(maxPort, c);
214
215         c.gridx = 0;
216         c.gridy = 4;
217         c.gridwidth = 1;
218         c.fill = GridBagConstraints.BOTH;
219         c.anchor = GridBagConstraints.CENTER;
220         mPanel.add(TNUM, c);
221
222         c.gridx = 1;
223         c.gridy = 4;
224         c.gridwidth = 3;
225         c.fill = GridBagConstraints.BOTH;
226         c.anchor = GridBagConstraints.CENTER;
227         mPanel.add(maxThread, c);
228
229         c.gridx = 0;
230         c.gridy = 5;
231         c.gridwidth = 3;
232         c.fill = GridBagConstraints.BOTH;
233         c.anchor = GridBagConstraints.CENTER;
234         mPanel.add(Submit, c);
235
236
237         c.gridx = 3;
238         c.gridy = 5;
239         c.gridwidth = 3;
240         c.fill = GridBagConstraints.BOTH;
241         c.anchor = GridBagConstraints.CENTER;
242         mPanel.add(saveButton, c);
243
244         c.gridx = 6;
245         c.gridy = 5;
246         c.gridwidth =4;
247         c.fill = GridBagConstraints.BOTH;
248         c.anchor = GridBagConstraints.CENTER;
249         mPanel.add(Cancel, c);
250
251         c.gridx = 0;
252         c.gridy = 6;
253         c.gridwidth = 10;
254         c.fill = GridBagConstraints.BOTH;
255         c.anchor = GridBagConstraints.CENTER;
256         mPanel.add(RST, c);
257
258         //设置文本域可以换行
259         Result.setLineWrap(true);
260         //设置文本域不可编辑
261         Result.setEditable(false);
262
263
264         c.gridx = 0;
265         c.gridy = 7;
266         c.gridwidth = 10;
267         c.gridheight = 4;
268         c.fill = GridBagConstraints.VERTICAL;
269         c.anchor = GridBagConstraints.CENTER;
270         mPanel.add(resultPane, c);
271
272         Container dPanel = DLGError.getContentPane();
273         dPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
274         dPanel.add(DLGINFO);
275         dPanel.add(Ok);
276
277
278         Submit.addActionListener(new SubmitAction());
279         Cancel.addActionListener(new CancelAction());
280         Ok.addActionListener(new OkAction());
281
282         //实现保存功能
283         saveItem.addActionListener(new java.awt.event.ActionListener(){
284             public void actionPerformed(java.awt.event.ActionEvent e){
285                 JFileChooser fc = new JFileChooser();
286                 int returnVal = fc.showSaveDialog(null);
287                 //单击保存按钮
288                 if( 0 == returnVal ){
289                     File saveFile = fc.getSelectedFile();
290                     try{
291                         FileWriter writeOut = new FileWriter( saveFile );
292                         writeOut.write(ThreadScan.Result.getText());
293                         writeOut.close();
294
295                     }catch( IOException ex ){ System.out.println("保存失败");}
296                 }
297             }
298         });
299         //实现退出功能
300         ActionListener li =  new java.awt.event.ActionListener(){
301             public void actionPerformed(java.awt.event.ActionEvent e){
302                 System.exit(0);
303             }
304         };
305         exitItem.addActionListener(li);
306         //实现帮助功能
307
308         ActionListener lil =  new java.awt.event.ActionListener(){
309             public void actionPerformed(java.awt.event.ActionEvent e){
310                 new AboutDialog();//
311             }
312         };
313         helpItem.addActionListener(lil);
314
315         ActionListener lill =  new java.awt.event.ActionListener(){
316             public void actionPerformed(java.awt.event.ActionEvent e){
317                 JFileChooser fc = new JFileChooser();
318                 int returnVal = fc.showSaveDialog(null);
319                 //单击保存按钮
320                 if( 0 == returnVal ){
321                     File saveFile = fc.getSelectedFile();
322                     try{
323                         FileWriter writeOut = new FileWriter(saveFile);
324                         writeOut.write(ThreadScan.Result.getText());
325                         writeOut.close();
326                     }catch(IOException ex ){ System.out.println("保存失败");}
327                 }else{
328                     return;//单击取消
329                 }
330
331             }
332         };
333         saveButton.addActionListener(lill);
334         main.setVisible(true);
335     }
336 }
337 /**
338  *
339  * @author Nevermore
340  *    实现取消功能
341  */
342 class CancelAction implements ActionListener{
343     public void actionPerformed( ActionEvent e){
344         System.exit(0);
345     }
346 }
347 /**
348  *
349  * @author Nevermore
350  *    实现确定按钮
351  */
352 class SubmitAction implements ActionListener{
353     public void actionPerformed( ActionEvent a){
354         int minPort;
355         int maxPort;
356         int maxThread;
357
358         int ip1 = 0;
359         int ip2 = 0;
360         int ip3 = 0;
361         int ipstart = 0;
362         int ipend = 0;
363
364         String ipaddress = "";
365         String nameHost = "";
366         ThreadScan.Result.setText("");
367         if( ThreadScan.Submit.isEnabled()){
368             ThreadScan.Submit.setEnabled(false);
369         }
370         /**
371          * 判断扫描类型
372          * 根据IP地址扫描 type = 0
373          *根据主机名称扫描type = 1
374          */
375         if( ThreadScan.radioIP.isSelected()){
376             TcpThread.type = 0;
377             //判断IP地址的前三位是否是int型
378             try{
379                 ip1 = Integer.parseInt(ThreadScan.fromip1.getText());
380             }catch( NumberFormatException e ){
381                 ThreadScan.DLGINFO.setText("错误的IP地址");
382                 ThreadScan.DLGError.setVisible(true);
383                 return;
384             }
385             try{
386                 ip2 = Integer.parseInt(ThreadScan.fromip2.getText());
387             }catch( NumberFormatException e ){
388                 ThreadScan.DLGINFO.setText("错误的IP地址");
389                 ThreadScan.DLGError.setVisible(true);
390                 return;
391             }
392             try{
393                 ip3 = Integer.parseInt(ThreadScan.fromip3.getText());
394             }catch( NumberFormatException e ){
395                 ThreadScan.DLGINFO.setText("错误的IP地址");
396                 ThreadScan.DLGError.setVisible(true);
397                 return;
398             }
399             try{
400                 ipstart = Integer.parseInt(ThreadScan.fromip4.getText());
401             }catch( NumberFormatException e ){
402                 ThreadScan.DLGINFO.setText("错误的IP地址");
403                 ThreadScan.DLGError.setVisible(true);
404                 return;
405             }
406             try{
407                 ipend = Integer.parseInt(ThreadScan.toip.getText());
408             }catch( NumberFormatException e ){
409                 ThreadScan.DLGINFO.setText("错误的IP地址");
410                 ThreadScan.DLGError.setVisible(true);
411                 return;
412             }
413
414             //判断是否是合理的IP地址
415             if(ip1 < 0 || ip1 > 255 || ip2 < 0 || ip2 > 255 ||
416                ip3 < 0 || ip3 > 255 || ipstart < 0 || ipstart > 255 ){
417                 ThreadScan.DLGINFO.setText("IP地址为0~255的整数");
418                 ThreadScan.DLGError.setVisible(true);
419                 return ;
420             }else{
421                 TcpThread.ip1 = ip1;
422                 TcpThread.ip2 = ip2;
423                 TcpThread.ip3 = ip3;
424                 TcpThread.ipstart = ipstart;
425             }
426             //判断目标IP地是否合理
427             if( ipend < 0 || ipend > 255 ){
428                 ThreadScan.DLGINFO.setText("目标IP地址的范围是0~255");
429                 ThreadScan.DLGError.setVisible(true);
430                 return;
431             }else{
432                 TcpThread.ipend = ipend;
433             }
434
435             ipaddress = "" + ip1 + ip2 + ip3 + ipstart;
436
437             /**
438              * 判断IP地址的有效性
439              */
440             try{
441                 TcpThread.hostAddress = InetAddress.getByName(ipaddress);
442             }catch( UnknownHostException e){
443                 ThreadScan.DLGINFO.setText("错误的IP或IP地址不可到达!");
444                 ThreadScan.DLGError.setVisible(true);
445                 return;
446             }
447
448             if( ThreadScan.radioHost.isSelected()){
449                 TcpThread.type = 1;
450                 /**
451                  * 判断主机名的有效性
452                  */
453                 try{
454                     TcpThread.hostAddress = InetAddress.getByName(ThreadScan.nameHost.getText());
455                 }catch( UnknownHostException e){
456                     ThreadScan.DLGINFO.setText("错误的域名或地址不可到达!");
457                     ThreadScan.DLGError.setVisible(true);
458                     return;
459                 }
460             }
461             /**
462              * 判断端口号的有效性
463              */
464             try{
465                 minPort = Integer.parseInt(ThreadScan.minPort.getText());
466                 maxPort = Integer.parseInt(ThreadScan.maxPort.getText());
467                 maxThread = Integer.parseInt(ThreadScan.maxThread.getText());
468             }catch( NumberFormatException e ){
469                 ThreadScan.DLGINFO.setText("错误的端口号或端口号和线程数必须为整数");
470                 ThreadScan.DLGError.setVisible(true);
471                 return;
472             }
473             /**
474              * 判断最小端口号的有效范围
475              * 判断条件大于0小于65535最大端口号大于最小端口号
476              */
477             if( minPort < 0 || minPort > 65535 || minPort > maxPort ){
478                 ThreadScan.DLGINFO.setText("端口号范围:0~65535,并且最大端口号应大于最小端口号!");
479                 ThreadScan.DLGError.setVisible(true);
480                 return;
481             }else{
482                 TcpThread.MIN_port = minPort;
483             }
484             /**
485              * 判断最大端口号的有效范围
486              */
487             if( maxPort < 0 || maxPort > 65535 || maxPort < minPort ){
488                 ThreadScan.DLGINFO.setText("端口号范围:0~65535,并且最大端口号应大于最小端口号!");
489                 ThreadScan.DLGError.setVisible(true);
490                 return;
491             }else{
492                 TcpThread.MAX_port = maxPort;
493             }
494             /**
495              * 判断线程数的有效范围
496              * 判断条件 大于1且小于200
497              */
498             if( maxThread < 1 || maxThread > 200 ){
499                 ThreadScan.DLGINFO.setText("线程数的有效范围是1~200");
500                 ThreadScan.DLGError.setVisible(true);
501                 return;
502             }
503             ThreadScan.Result.append("线程数" + ThreadScan.maxThread.getText() + "\n");
504
505             /**
506              * 启动线程
507              */
508             for( int i = 0; i < maxThread; i++ ){
509                 new TcpThread("T" + i, i).start();
510             }
511         }
512     }
513 }
514 /**
515  *
516  * @author Administrator
517  *    错误对话框
518  */
519 class OkAction implements ActionListener{
520     public void actionPerformed( ActionEvent e){
521         ThreadScan.DLGError.dispose();
522     }
523 }
import javax.swing.*;
import java.awt.*;

public class AboutDialog extends JDialog{
    JPanel JMainPane = new JPanel();
    JTabbedPane jTabbedPane = new JTabbedPane();

    private JPanel JPanel1 = new JPanel();
    private JPanel JPanel2 = new JPanel();

    private JTextArea jt1 = new JTextArea(6, 6);
    private JTextArea jt2 = new JTextArea(6, 6);

    /**
     * 构造函数
     */
     public AboutDialog(){
         setTitle("Scaner");
         setSize(300,200);
         setResizable(false);
         setDefaultCloseOperation( WindowConstants.DISPOSE_ON_CLOSE);

         Container c = this.getContentPane();

         jt1.setSize(260,200);
         jt2.setSize(260,200);
         jt1.setEditable(false);
         jt2.setEditable(false);
         jt1.setLineWrap(true);
         jt2.setLineWrap(true);

         jt1.setText("");
         jt1.setFont(new Font("楷体_GB2312", java.awt.Font.BOLD, 13));
         jt2.setText("");
         jt2.setFont(new Font("楷体_GB2312", java.awt.Font.BOLD, 13));

         jt1.setForeground(Color.black);
         jt2.setForeground(Color.black);

         JPanel1.add(jt1);
         JPanel2.add(jt2);

         jTabbedPane.setSize(300,200);
         jTabbedPane.addTab("扫描原理", null, JPanel1, null);
         jTabbedPane.addTab("使用说明", null, JPanel2, null);
         JMainPane.add(jTabbedPane);
         c.add(JMainPane);
         pack();
         this.setVisible(true);
     }
}
时间: 2024-10-29 13:10:17

多线程实现端口扫描的相关文章

使用Java开发多线程端口扫描工具(二)

一 介绍 这一篇文章是紧接着上一篇文章(http://www.zifangsky.cn/2015/12/使用java开发多线程端口扫描工具/)写的,端口扫描的原理不用多少,我在上一篇文章中已经说过了,至于目的大家都懂得.在这一篇文章里,我主要是对端口扫描工具的继续完善,以及写出一个比较直观的图形界面出来,以方便我们测试使用.界面如下: 这个工具主要是实现了以下几点功能:(1)两种扫描方式,一种是只扫描常见端口,另一种是设置一个起始和结束端口,依次探测.当然,原理很简单,用for循环就可以了:(2

Windows多线程端口扫描

还不是很了解多线程,先简单运用下. 1 /* 2 2015.5 HT 3 多线程端口扫描 4 5 netstat -an 6 7 */ 8 9 #include <iostream> 10 #include <process.h> 11 #include <winsock2.h> 12 #pragma comment(lib,"ws2_32.lib") 13 using namespace std; 14 15 // 线程传递的端口参数 16 typ

Python3实现TCP端口扫描

在渗透测试的初步阶段通常我们都需要对攻击目标进行信息搜集,而端口扫描就是信息搜集中至关重要的一个步骤.通过端口扫描我们可以了解到目标主机都开放了哪些服务,甚至能根据服务猜测可能存在某些漏洞. TCP端口扫描一般分为以下几种类型: TCP connect扫描:也称为全连接扫描,这种方式直接连接到目标端口,完成了TCP三次握手的过程,这种方式扫描结果比较准确,但速度比较慢而且可轻易被目标系统检测到. TCP SYN扫描:也称为半开放扫描,这种方式将发送一个SYN包,启动一个TCP会话,并等待目标响应

告别脚本小子【编写端口扫描工具】

前言Windows系统默认开放了很多端口,通常这些端口意味着该主机运行着大家都知道的服务,比如TCP端口21-FTP服务,TCP端口80-HTTP服务,有些服务就有可能存在公开的漏洞,因此可以说主机上每一个开放的端口都可能成为一条入侵的捷径.当然,网上存在很多端口扫描工具,但是我们总不能只知道使用别人的工具,一是这些工具别人编写的时候有没有加入后门,二是如果只会用别人的工具,最终也只能是一个脚本小子,所以我们自己来编写一款实用的端口扫描工具. 一.基础知识 1.1.线程 线程,有时被称为轻量级进

端口扫描工具

简单的多线程端口扫描工具 可以接收IP地址作为参数,如果不接参数,则默认扫描本机的端口 1 #!/usr/bin/python 2 3 import socket 4 import time 5 import argparse 6 import threading 7 8 def arg_process(): 9 argparser=argparse.ArgumentParser(description="Port Scaner") 10 argparser.add_argument(

Python 脚本学习笔记(五)集中式病毒扫描,端口扫描以及分段数据库操作

Clam AntiVirus是一个免费而且开放源码的防毒软件,软件与病毒库的更新由开源社区免费发布,目前ClamdAV主要为Linux.Uinux系统提供病毒扫描查杀pyClamad是一个python的第三方模块,可让python直接使用ClamAV病毒扫描守护进程clamd来实现一个高效的病毒检测功能. 一.实现集中式的病毒扫描 1.安装clamavp clamd 服务的相关程序包 yum install clamav clamd clamav-update -y chkconfig clam

端口扫描技术

目前主要的端口扫描技术有以下几种:1.TCP connect Scan(TCP连接扫描)这 种方法也称之为“TCP全连接扫描”.它是最简单的一种扫描技术,所利用的是TCP协议的3次握手过程.它直接连到目标端口并完成一个完整的3次握手过 程(SYN.SYN/ACK和ACK).操作系统提供的“connect()”函数完成系统调用,用来与目标计算机的端口进行连接.如果端口处于侦听状 态,那么“connect()”函数就能成功.否则,这个端口是不能用的,即没有提供服务.TCP连接扫描技术的一个 最大的优

端口扫描 多方式协同实现

最后一个暑假,因为已经有一个项目在手,不想把自己整得太累,但又不能太闲,于是选择了一个可以拖拖踏踏做的简单事情,做一套端口扫描.这种平时集中精力几天就可以做完的事情,结果真是拖拖踏踏了很久才做完. 进入正题.端口扫描,即是通过一些扫描的手段来探知某些ip的端口情况,主要为探知端口的开放情况与端口的应用类型. 由于各个设备的系统与防火墙的差异,某一单一的端口扫描方式难以应用于所有的系统,而且扫描方并不知道扫描对方的系统情况.为了应对不同情况,有必要采用多种扫描方式协同扫描.在此我使用了connec

利用nmap进行特定端口扫描

1.使用Python的nmap进行特定的端口扫描,包括各种常用的数据库端口,web端口,一些自定义的端口,使用nmap之前需要确定本机已经安装了nmap包2.其中ret()函数是获取ip列表3.最后print出来的是一个json的结果,方便使用zabbix进行监控4.因为ip较多,需要进行多线程获取结果,时间比较久,建议先把结果写到本地,然后再用zabbix进行自动发现并监控5.Python语法不够精通,欢迎批评指导 #!/usr/bin/python #-*-coding:utf-8-*- i