Scanning IP by thread
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, December 3, 2002 01:35 PM

I have any problems with Threads: The following part of code allows to scan all opened ports of one determinate IP address. The program has been developped with jbuilder and works correctly and very fast , but when the process has terminated its activity it cannot works again and run another scanning process. If I exit from the system and I launch the program again it continue to works regolary.   Thread t = new Thread(){ public void run() { int i = 0; Socket s = null; String host = jTextField2.getText()+"."+jTextField3.getText()+ ".&q   More>>

I have any problems with Threads:



The following part of code allows to scan all opened ports of one determinate
IP address. The program has been developped with jbuilder and works correctly
and very fast , but when the process has terminated its activity it cannot works
again and run another scanning process.



If I exit from the system and I launch the program again it continue to works
regolary.



 



Thread t = new Thread(){



public void run() {





int i = 0;



Socket s = null;



String host = jTextField2.getText()+"."+jTextField3.getText()+



"."+jTextField4.getText()+"."+jTextField5.getText();



String portrange1 = jTextField8.getText();



String portrange2 = jTextField9.getText();



int a = Integer.parseInt(portrange1);



int b = Integer.parseInt(portrange2);



String timeout01 = jTextField10.getText();



int timeout = Integer.parseInt(timeout01);



for ( i=a; i



try {



s = new Socket();



s.connect(new InetSocketAddress(host,i),timeout);



s.close();





}





catch (Exception ev){}



jProgressBar1.setMinimum(a);



jProgressBar1.setMaximum(b);



jProgressBar1.setValue(i+1);







jTextField13.setText("Scanning IP address : "+host+" on port : "+i);





if (s.getPort()==i){



jTextArea3.append("Find opened port : "+s.getPort());

jTextArea3.append("
");









}



}



}



};

private Border border19;

private JTextArea jTextArea3 = new JTextArea();

private Border border20;

private JButton jButton7 = new JButton();

private JTextField jTextField11 = new JTextField();

private JTextField jTextField12 = new JTextField();

private JButton jButton13 = new JButton();

private JButton jButton14 = new JButton();

private JLabel jLabel16 = new JLabel();

private JLabel jLabel17 = new JLabel();

private JTextArea jTextArea4 = new JTextArea();

private Border border21;

private JTextField jTextField13 = new JTextField();

private JTextField jTextField14 = new JTextField();

private JTextField jTextField15 = new JTextField();

private JTextField jTextField16 = new JTextField();

private JTextField jTextField17 = new JTextField();

private JTextField jTextField18 = new JTextField();

private JTextField jTextField19 = new JTextField();

private JTextField jTextField110 = new JTextField();

private JButton jButton15 = new JButton();

private JButton jButton16 = new JButton();

private JScrollPane jScrollPane2 = new JScrollPane();

private JTextArea jTextArea5 = new JTextArea();

private JTextArea jTextArea2 = new JTextArea();





void jButton11_actionPerformed(ActionEvent e) {



t.start();





try {




??????// what code i have to add ???


}

catch (Exception ev) {}



}



 



 



Can you help me



 



Thanks , Pier Luigi

   <<Less

Re: Scanning IP by thread

Posted By:   hari_haran  
Posted On:   Thursday, December 5, 2002 05:23 AM

hi ,
This suggestion may probably work try out ,

What u do is make an innerclass which extends thread
Now , on action performed create new thread and now call start , this will definitely workout (ie)

CMyThread mtharead = new CMyThread() ;

mthread.start() ;

write all these stuff at the place where u have written start function







bye

Hari Haran.K

hari_haran_k@hotmail.com


Re: Scanning IP by thread

Posted By:   Lasse_Koskela  
Posted On:   Tuesday, December 3, 2002 02:32 PM

Once a thread's run() method has completed, the thread cannot be restarted just by calling start() again. You need to do some kind of eternal looping within the run() method.


Check this out.

About | Sitemap | Contact