⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scanipsdemon.java

📁 NetGUI v0.4.1 INSTALL Instructions Pedro de la
💻 JAVA
字号:
/* * Copyright (C) 2005, 2006  * Santiago Carot Nemesio * * This file is part of NetGUI. * * NetGUI is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * NetGUI is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  * You should have received a copy of the GNU General Public License * along with NetGUI; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *   */import edu.umd.cs.piccolo.*;import edu.umd.cs.piccolo.PCanvas;import edu.umd.cs.piccolo.nodes.*;import edu.umd.cs.piccolox.*;import edu.umd.cs.piccolox.nodes.*;import java.util.*;public class ScanIPsDemon extends Thread{	private PLayer nodeLayer;	public ScanIPsDemon (PLayer nodeLayer)	{		this.nodeLayer = nodeLayer;	}	public void run ()	{		Object obj;		do		{			Iterator i = Collections.list(Collections.enumeration(nodeLayer.getAllNodes())).iterator();			while (i.hasNext())			{				obj = i.next();				if (obj instanceof NKSystem)					if (((NKSystem)obj).isStarted())					{						//System.out.println("Leer en " + ((NKNode)obj).getName());						readIP((NKSystem)obj);					}			}			try			{				sleep(2000);			}catch(Exception e){;}					}while(true);	}	private void readIP (NKSystem node)	{		TelnetSocket ts = NodeTelnetCommunicator.getTelnetSocket(node);		if (ts!=null)		{			if (ts.send("ifconfig"))			{				String txt = ts.getOutputResponse();				if (txt != null)					analizeInterfaces(txt, node);			}		}	}	private void analizeInterfaces (String result, NKSystem node)	{		HashMap eth_ip = new HashMap ();		String eth = "eth";		String ethx;		while (result.indexOf(eth) != -1)		{			ethx = result.substring(result.indexOf(eth),result.indexOf("Interrupt"));			getEthConf(ethx,eth_ip);			result = result.substring((result.indexOf("Interrupt")+9),result.length());		}		node.updateEthernets(eth_ip);			}		private void getEthConf (String ethx, HashMap eth_ip)	{		StringTokenizer st = new StringTokenizer (ethx);		String ethernet="", ip="";		for (int i = 0; i<=7; i++)		{			String aux = st.nextToken();			if (i==0) ethernet = aux;			if (i==7) ip = aux.substring(aux.indexOf(":")+1,aux.length());		}		eth_ip.put(ethernet,ip);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -