1 2 23 24 package net.fenyo.gnetwatch; 25 26 import net.fenyo.gnetwatch.activities.*; 27 import net.fenyo.gnetwatch.targets.*; 28 import net.fenyo.gnetwatch.GUI.*; 29 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 import org.dom4j.Document; 33 import org.dom4j.Node; 34 35 import java.util.*; 36 37 42 43 public class Main { 44 private static Log log = LogFactory.getLog(Main.class); 45 private final Config config; 46 private GUI gui = null; 47 private final CaptureManager capture_mgr; 48 private CaptureManager.HandlePacket handler = null; 49 50 55 public Main(final Config config, final CaptureManager capture_mgr) { 56 this.config = config; 57 this.capture_mgr = capture_mgr; 58 } 59 60 65 public void setGUI(final GUI gui) { 66 this.gui = gui; 67 } 68 69 74 public void startDiscover() { 76 handler = 77 new CaptureManager.HandlePacket() { 78 public void document(final Document packet) { 79 final List<Node> nodes = packet.selectNodes("/packet/proto[@name='ip']/field[@name='ip.addr']"); 80 if (nodes.size() == 2) { 81 final String srcaddr = nodes.get(0).valueOf("@show"); 82 final String dstaddr = nodes.get(1).valueOf("@show"); 83 86 TargetIPv4.addTargetIPv4(gui, srcaddr); 88 TargetIPv4.addTargetIPv4(gui, dstaddr); 89 } 90 91 final List<Node> nodes_ipv6 = packet.selectNodes("/packet/proto[@name='ipv6']/field[@name='ipv6.addr']"); 92 if (nodes_ipv6.size() == 2) { 93 final String srcaddr = nodes_ipv6.get(0).valueOf("@show"); 94 final String dstaddr = nodes_ipv6.get(1).valueOf("@show"); 95 96 TargetIPv6.addTargetIPv6(gui, srcaddr); 98 TargetIPv6.addTargetIPv6(gui, dstaddr); 99 } 100 } 101 }; 102 try { 103 capture_mgr.registerListener("ip", handler); 104 } catch (final InterruptedException ex) { 105 log.error("Exception", ex); 106 } 107 } 108 109 114 public void stopDiscover() { 116 try { 117 capture_mgr.unRegisterListener("ip", handler); 118 } catch (final InterruptedException ex) { 119 log.error("Exception", ex); 120 } 121 } 122 } 123 | Popular Tags |