guys, I have a GUI that scan a range of ip address when press "scan" button; however, I'm having trouble displaying the result in the textArea box. I'm using a threads for my execution. here's the action performed when press the scan button. How could I get the output of the scan and put it into a textArea.setText(...);
IPrange netRange = new IPrange(); ArrayList<String> r = netRange.getRange(); public void StartIPscan() { String ipFrom = ipTextFrom.getText(); String ipTo = ipTextTo.getText(); netRange.setFromip(ipFrom); netRange.setToip(ipTo); netRange.StrToIP(); netRange.calcNetwork(); /** * ping sweep network */ Runnable scan = new IPscanner(r); Thread t = new Thread(scan); t.start(); }
here's the IPrange class that implements Runnable interface
import java.io.*; import java.net.*; import java.util.*; public class IPscanner implements Runnable{ private String ipadd = ""; ArrayList<String> block; public IPscanner(ArrayList r) { block = r; } public void run(){ boolean ping = false; //ipadd = block.size()+""; ipadd = "Scanning network "+"\""+block.get(0)+"...\""+"\n"; for(int i = 0; i < block.size(); i++) { try { int timeout = 1000; InetAddress address = InetAddress.getByName(block.get(i)); //scanProgressBar.setValue(i);//updating progress bar ping = address.isReachable(timeout); if(ping == true) { ipadd += block.get(i)+" ---> is alive!"+"\n"; } else { ipadd += block.get(i)+"\n"; } } catch(IOException e) { System.out.println(e); } } } public void setIPadd(String s) { ipadd = s; } public String getIPadd() { return ipadd; } }