?? todoscan.java
字號:
package javascan;/** * Title:掃描實體程序 * Description: * Copyright: Copyright (c) 2001 * Company: * @author * @version 1.0 */import java.util.*;import java.io.*;import java.net.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.tree.*;public class todoscan extends Thread{ public int runstop=0; public JProgressBar scanbar; public JButton bstart,bstop; public int usefile=0; public javax.swing.JLabel showlabel; String sinfo; Socket s; DefaultMutableTreeNode newnode; TreeNode[] nodes; String host; DefaultTreeModel model; JTree tree; int intfromport,inttoport; public todoscan(DefaultTreeModel inmodel,JTree intree,int fport,int tport,String tohost) { model=inmodel; tree=intree; intfromport=fport; inttoport=tport; host=tohost; } void usefilescan() { // DefaultMutableTreeNode root=(DefaultMutableTreeNode)model.getRoot(); //得到ROOT DefaultMutableTreeNode newroot=new DefaultMutableTreeNode(host); model.insertNodeInto(newroot,root,root.getChildCount()); nodes=model.getPathToRoot(newroot); tree.makeVisible(new TreePath(nodes)); root=newroot;// root=(DefaultMutableTreeNode)root.getChildAt(0); //使ROOT點為新添加的// root.get InputStream in=javascan.todoscan.class.getResourceAsStream("portlist.properties"); try { //res try ResourceBundle portlist=new PropertyResourceBundle(in); java.util.Enumeration en=portlist.getKeys(); while (en.hasMoreElements()) { if (runstop==1) return; String string=en.nextElement().toString(); System.out.println(host+" "+string+"="+portlist.getString(string)); int n=java.lang.Integer.parseInt(string); try { s=new Socket(host,n); s.setSoTimeout(1000); BufferedReader rr=new BufferedReader(new InputStreamReader(s.getInputStream())); try { sinfo=rr.readLine();} catch (java.io.IOException errr){sinfo=null;} //加新結點 newnode=new DefaultMutableTreeNode(" "+n+" "+portlist.getString(string)); if (sinfo!=null) newnode.add(new DefaultMutableTreeNode(sinfo)); model.insertNodeInto(newnode,root,root.getChildCount()); // newnode.add(new DefaultMutableTreeNode("kkkk")); //顯示新結點 nodes=model.getPathToRoot(newnode); tree.makeVisible(new TreePath(nodes));// tree.scrollPathToVisible(new TreePath(nodes)); //顯示新信息 s.close(); } catch(java.io.IOException err1){;} //end try s if (showlabel!=null) showlabel.setText("scan port at "+n); if (scanbar!=null) scanbar.setValue(scanbar.getValue()+1); } //end while } catch (java.io.IOException e1) {System.out.println(e1);}; //rec try end } void notusefilescan() { DefaultMutableTreeNode root=(DefaultMutableTreeNode)model.getRoot(); //得到ROOT DefaultMutableTreeNode newroot=new DefaultMutableTreeNode(host); model.insertNodeInto(newroot,root,root.getChildCount()); nodes=model.getPathToRoot(newroot); tree.makeVisible(new TreePath(nodes)); root=newroot; for(int n=intfromport;n<inttoport;n++) { System.out.println(host+ " "+"port="+n); if (runstop==1) return; try { s=new Socket(host,n); s.setSoTimeout(1000); BufferedReader rr=new BufferedReader(new InputStreamReader(s.getInputStream())); try { sinfo=rr.readLine();} catch (java.io.IOException errr){sinfo=null;}// sinfo=( //加新結點 newnode=new DefaultMutableTreeNode(" "+n); if (sinfo!=null) newnode.add(new DefaultMutableTreeNode(sinfo)); model.insertNodeInto(newnode,root,root.getChildCount()); //顯示新結點 nodes=model.getPathToRoot(newnode); tree.makeVisible(new TreePath(nodes));// tree.scrollPathToVisible(new TreePath(nodes)); //顯示新信息 s.close(); } catch(java.io.IOException err1){;} if (showlabel!=null) showlabel.setText("hostscan port at "+n); //System.out.println(n); /* try {sleep(1000);} catch (java.lang.InterruptedException err1) {;} */ } //end for } public void run() { if (bstart!=null) bstart.setEnabled(false); if (bstop!=null) bstop.setEnabled(true); if (usefile==0) {notusefilescan();} else {usefilescan();} if (bstart!=null) bstart.setEnabled(true); if (bstop!=null) bstop.setEnabled(false); runstop=1; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -