Znn3bq.jpeg
²é¿´: 263  |  »Ø¸´: 0
µ±Ç°Ö÷ÌâÒѾ­´æµµ¡£

aisingioro

½ð³æ (ÕýʽдÊÖ)


[×ÊÔ´] ¡¾Ô­´´¡¿¶àÏ̶߳˿ÚɨÃ裨Java£©¡¾ÒÑËÑÎÞÖØ¸´¡¿

×î½ü¸´Ï°Java£¬×¼±¸¿¼ÊÔ£¬Ð´Á˸ö¶àÏ̶߳˿ÚɨÃèµÄС³ÌÐò£¬Çë´ó¼ÒÖ¸½Ì¡£
Ô´´úÂëÈçÏ£º
===============================================
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;


class scanPort extends Thread{
    String host;
    int startPort;
    int endPort;
    int tag;
    display d;
   
    volatile boolean runStatus;
        
    scanPort(String h,int sp,int ep,int tg,display dis){
        super();
        host=h;
        startPort=sp;
        endPort=ep;
        tag=tg;
        d=dis;
        runStatus=true;
    }
    public synchronized void goRun()  {
            try{
                   runStatus=true;
             notify();
         //    System.out.println("notify");
            }catch(Exception e){
                    System.out.println(e.toString());
            }
    }

    public synchronized void goWait() throws InterruptedException{
            try{
           while (runStatus==false){
              wait();
           }
        }catch(Exception e){
                    System.out.println(e.toString());
            }
    }   
    public void  run(){
        for(int i=startPort;i<=endPort;i++){
            try{
                goWait();
                Socket s=new Socket(host,i);
                synchronized (d.jTextArea1){
                    d.jTextArea1.setText(d.jTextArea1.getText()+"Host:"+host.toString()+" Port: "+i+" is Opening."+tag+"Ïß³Ì"+"\n");
                }               
            }
            catch(IOException  e){
                synchronized (d.jTextArea1){
                    d.jTextArea1.setText(d.jTextArea1.getText()+"Host:"+host.toString()+" Port: "+i+" is Closed."+tag+"Ïß³Ì"+"\n");
                }               
            }
            catch(InterruptedException e){
                System.out.println(e.toString());
            }
        }
    }
}
class display extends JFrame {

    int threadNumber;
    int start;
    int end;
    String host;
    scanPort s[];
    int status;
   
   
    JButton jButton1;
    JButton jButton2;
    JButton jButton3;
    JLabel jLabel1;
    JLabel jLabel2;
    JLabel jLabel3;
    JLabel jLabel4;
    JMenu jMenu1;
    JMenuBar jMenuBar1;
    JMenuItem jMenuItem1;
    JScrollPane jScrollPane1;
    JTextArea jTextArea1;
    JTextField jTextField1;
    JTextField jTextField2;
    JTextField jTextField3;
   
    selectThreadNumber se;
   
    public display() {
           
           threadNumber=1;
           status=0;
           
           jButton1=new JButton("¿ªÊ¼É¨Ãè");
           jButton2=new JButton("ÔÝͣɨÃè");
           jButton3=new JButton("ֹͣɨÃè");
           jLabel1=new JLabel("ÇëÊäÈëҪɨÃèµÄIPµØÖ·£º");
           jLabel2=new JLabel("¿ªÊ¼¶Ë¿Ú£º");
           jLabel3=new JLabel("½áÊø¶Ë¿Ú£º");
           
           jMenuBar1=new JMenuBar();
           jMenu1=new JMenu("ÉèÖÃ");
           jMenuItem1=new JMenuItem("ÉèÖÃÏß³ÌÊý:");
           jMenu1.add(jMenuItem1);
           jMenuBar1.add(jMenu1);
           
           jTextArea1=new JTextArea();
           jScrollPane1=new JScrollPane(jTextArea1);
                                 
           jTextField1=new JTextField();
           jTextField2=new JTextField("0");
           jTextField3=new JTextField("65535");   
           
           this.add(jMenuBar1);
           this.add(jLabel1);
           this.add(jTextField1);
           this.add(jLabel2);
           this.add(jTextField2);
           this.add(jLabel3);
           this.add(jTextField3);
           this.add(jButton1);
           this.add(jButton2);
           this.add(jButton3);
           this.add(jScrollPane1);
           
           this.setLayout(null);
           jMenuBar1.setSize(300, 20);
           jMenuBar1.setLocation(0, 0);
           jLabel1.setSize(150, 20);
           jLabel1.setLocation(0,30);
           jTextField1.setSize(140, 20);
           jTextField1.setLocation(150,30);
           jLabel2.setSize(80,20);
           jLabel2.setLocation(0,60);
           jTextField2.setSize(60,20);
           jTextField2.setLocation(70,60);
           jLabel3.setSize(80,20);
           jLabel3.setLocation(150,60);
           jTextField3.setSize(60,20);
           jTextField3.setLocation(220,60);
           jButton1.setSize(90,20);
           jButton1.setLocation(5, 90);
           jButton2.setSize(90,20);
           jButton2.setLocation(100, 90);
           jButton3.setSize(90,20);
           jButton3.setLocation(195, 90);
           jScrollPane1.setSize(300,150);
           jScrollPane1.setLocation(0,120);   
           
           jButton1.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                   jButton1ActionPerformed(e);                  
               }
           });
           
           jButton2.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                   jButton2ActionPerformed(e);
               }
           });
           
           jButton3.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                   jButton3ActionPerformed(e);
               }
           });
           
           jMenuItem1.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                   jMenuItem1ActionPerformed(e);
               }
           });           
    }   
     
    private void jButton1ActionPerformed(ActionEvent evt) {                                         
        s=new scanPort[threadNumber];
        host=jTextField1.getText();
        end=Integer.parseInt(jTextField3.getText());
        start=Integer.parseInt(jTextField2.getText());
        int theNumberOfPort=end-start+1;
        int everyThread[][]=new int[threadNumber][2];
        for(int i=0;i             everyThread[0]=(theNumberOfPort/threadNumber)*i+start;
            if((everyThread[0]+theNumberOfPort/threadNumber-1)<=end){
                everyThread[1]=everyThread[0]+theNumberOfPort/threadNumber-1;
            }
            else{
                everyThread[1]=end;
            }
            s=new scanPort(host,everyThread[0],everyThread[1],i+1,this);
            s.start();
        }                     
    }   
    private void jButton2ActionPerformed(ActionEvent evt) {
        if(status==0){
          jButton2.setText("¼ÌÐøÉ¨Ãè");
          status=1;
          for(int i=0;i                s.runStatus=false;               
          }
       }
       else{
         jButton2.setText("ÔÝͣɨÃè");
         status=0;   
         for(int i=0;i             
              s.goRun();                                    
        }
      }  
  }
    private void jButton3ActionPerformed(ActionEvent evt) {
        status=0;
        for(int i=0;i                 s.stop();
         }
    }
   
    private void jMenuItem1ActionPerformed(ActionEvent evt){
        selectThreadNumber sel=new selectThreadNumber(this);
        sel.addWindowListener(new WindowAdapter(){
            public void widnowClosing(WindowEvent e){
                System.exit(0);
            }
        });
        sel.show();  
    }
   
    public static void main(String args[]) {
      display dis=new display();
      dis.setTitle("PortScaner");
      dis.setSize(300, 300);
      dis.addWindowListener(new WindowAdapter(){
          public void windowClosing(WindowEvent e){
              System.exit(0);
          }
      });
      dis.show();
    }
}      

    class selectThreadNumber extends JFrame{
        JComboBox numberOfThread;
        JLabel lb1;
        JButton btn1;
        JButton btn2;
        int thNum;
        display d;
        
        selectThreadNumber(display dis){
           d=dis;
           
           lb1=new JLabel("ÇëÑ¡ÔñÏß³ÌÊý£º ");
           btn1=new JButton("È·¶¨");
           btn2=new JButton("È¡Ïû");
            
           numberOfThread=new JComboBox();
           numberOfThread.addItem("1");
           numberOfThread.addItem("2");
           numberOfThread.addItem("3");
           numberOfThread.addItem("4");
           numberOfThread.addItem("5");
           numberOfThread.addItem("6");
           numberOfThread.addItem("7");
           numberOfThread.addItem("8");
           numberOfThread.addItem("9");
           numberOfThread.addItem("10");
           numberOfThread.addItem("11");
           numberOfThread.addItem("12");
           numberOfThread.addItem("13");
           numberOfThread.addItem("14");
           numberOfThread.addItem("15");
           numberOfThread.addItem("16");
           
           this.setLayout(null);
           this.add(lb1);
           this.add(numberOfThread);
           this.add(btn1);
           this.add(btn2);
           lb1.setSize(150,20);
           lb1.setLocation(10,10);
           numberOfThread.setSize(100,20);
           numberOfThread.setLocation(170,10);
           btn1.setSize(70,20);
           btn1.setLocation(30,50);
           btn2.setSize(70,20);
           btn2.setLocation(180,50);
           this.setSize(300, 100);
           this.setTitle("Select thread number");
           
           btn1.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent e){
                   btn1ActionPerformed(e);
               }
           });
           
           
           btn2.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent e){
                   btn2ActionPerformed(e);
               }
           });
        }
        
        private void btn1ActionPerformed(ActionEvent evt){
            thNum=numberOfThread.getSelectedIndex()+1;   
            this.setVisible(false);
            d.threadNumber=thNum;
        }
        private void btn2ActionPerformed(ActionEvent evt){
            this.dispose();
        }
    }
===============================================
±£´æÎªscaner.java
jdk1.6.0±àÒëͨ¹ý²¢ÕýÈ·ÔËÐУ¡

[ Last edited by bslt on 2009-4-14 at 18:00 ]
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ aisingioro µÄÖ÷Ìâ¸üÐÂ
¡î ÎÞÐǼ¶ ¡ï Ò»ÐǼ¶ ¡ï¡ï¡ï ÈýÐǼ¶ ¡ï¡ï¡ï¡ï¡ï ÎåÐǼ¶
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] 268·Ö085602»¯Ñ§¹¤³Ìµ÷¼Á +29 ÔÂÕÕ»¨ÁÖ¡£ 2026-04-09 29/1450 2026-04-12 18:16 by zhouxiaoyu
[¿¼ÑÐ] µçÆø¹¤³Ìר˶320Çóµ÷¼Á +5 СÂé×Ó111 2026-04-10 5/250 2026-04-12 10:47 by zhouyuwinner
[¿¼ÑÐ] 313Çóµ÷¼Á +5 Óà°Ú°ÚÊÇ´ó¸ç 2026-04-11 5/250 2026-04-12 10:34 by Öí»á·É
[¿¼ÑÐ] 0854µ÷¼Á +12 ³¤¹­°Á 2026-04-09 13/650 2026-04-12 09:56 by ÄæË®³Ë·ç
[»ù½ðÉêÇë] ɽ¶«Ê¡»ù½ð2026 +5 jerry681 2026-04-08 6/300 2026-04-12 08:33 by kudofaye
[¿¼ÑÐ] 366Çóµ÷¼Á +7 ²»ÖªÃûµÄСئ 2026-04-11 7/350 2026-04-11 16:45 by PeggyPeng17
[¿¼ÑÐ] »¹Óл¯¹¤¶þÂÖµ÷¼ÁµÄѧУÂð 5+14 »¯¹¤ÈË999 2026-04-09 48/2400 2026-04-11 10:27 by 89436494
[¿¼ÑÐ] 275Çóµ÷¼Á +9 1624447980 2026-04-08 10/500 2026-04-11 10:20 by Delta2012
[¿¼ÑÐ] 085402ͨÐŹ¤³Ìµ÷¼Á£¬ÓÐ4Ïîѧ¿Æ¾ºÈü¹ú½±£¨µçÈü¹ú¶þ£©£¬Ë¶Ê¿Ñо¿Éúµ÷¼Á×Ô¼öÐÅ¡£ +5 mÓÀo²»vÑÔoÆúm 2026-04-09 5/250 2026-04-11 09:33 by zhq0425
[¿¼ÑÐ] ÉúÎïѧ308·ÖÇóµ÷¼Á£¨Ò»Ö¾Ô¸»ª¶«Ê¦´ó£©×ö¹ý·Ö×ÓʵÑé +8 ÏàÐűػá¹ââÍòÕ 2026-04-07 9/450 2026-04-10 21:03 by zhouxiaoyu
[¿¼ÑÐ] 314Çóµ÷¼Á +23 wakeluofu 2026-04-09 24/1200 2026-04-10 15:31 by MOF_Catal
[¿¼ÑÐ] 0702ÎïÀíѧѧ˶299Çóµ÷¼Á +6 ÆîÆâÁ¬ 2026-04-06 6/300 2026-04-10 11:10 by Roomoo
[¿¼ÑÐ] Ò»Ö¾Ô¸ÖÐÄÏ´óѧÎïÀíѧ£¬Ó¢Ò»66£¬Çóµ÷¼Á +4 ³¤ÑÌì½ì» 2026-04-08 5/250 2026-04-10 10:31 by Ó±¹û¶ù
[¿¼²©] ²©Ê¿×Ô¼ö +7 ¿É¿ÉСÅÖ 2026-04-08 7/350 2026-04-10 08:28 by kimhero
[¿¼ÑÐ] 085601³õÊÔ330·ÖÕÒµ÷¼Á +10 Á÷ÐÄÄ̻ưül 2026-04-09 10/500 2026-04-10 08:14 by Sammy2
[¿¼ÑÐ] 085404£¬285·ÖÇóµ÷¼Á +12 Þ±Þ±¿¼ÑÐ 2026-04-07 14/700 2026-04-09 23:10 by parmtree
[¿¼ÑÐ] 337Çóµ÷¼Á +4 Gky09300550£¬ 2026-04-09 4/200 2026-04-09 17:18 by ÅÁ¶ûÂíÀ­ÌØ
[¿¼ÑÐ] 327Çóµ÷¼Á +12 Xxjc1107. 2026-04-06 12/600 2026-04-08 16:46 by luoyongfeng
[¿¼ÑÐ] 071000ÉúÎïѧ£¬Ò»Ö¾Ô¸ÉîÛÚ´óѧ296·Ö£¬Çóµ÷¼Á +12 TIckLw 2026-04-06 13/650 2026-04-07 20:34 by lijunpoly
[¿¼ÑÐ] 312Çóµ÷¼Á +4 LR6 2026-04-06 4/200 2026-04-07 08:42 by jp9609
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û