📄 todoscan.java~49~
字号:
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()); 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(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()); root=newroot; for(int n=intfromport;n<inttoport;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); // System.out.println("port="+n+" sinfo="+sinfo); 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 + -