Source Code Cross Referenced for ActionNmap.java in  » Net » GNetWatch » net » fenyo » gnetwatch » actions » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » GNetWatch » net.fenyo.gnetwatch.actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * GNetWatch
003:         * Copyright 2006, 2007 Alexandre Fenyo
004:         * gnetwatch@fenyo.net
005:         *
006:         * This file is part of GNetWatch.
007:         *
008:         * GNetWatch is free software; you can redistribute it and/or modify
009:         * it under the terms of the GNU General Public License as published by
010:         * the Free Software Foundation; either version 2 of the License, or
011:         * (at your option) any later version.
012:         *
013:         * GNetWatch is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with GNetWatch; if not, write to the Free Software
020:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
021:         */
022:
023:        package net.fenyo.gnetwatch.actions;
024:
025:        import net.fenyo.gnetwatch.*;
026:        import net.fenyo.gnetwatch.GUI.GUI;
027:        import net.fenyo.gnetwatch.actions.Action.InterruptCause;
028:        import net.fenyo.gnetwatch.activities.Background;
029:        import net.fenyo.gnetwatch.data.*;
030:        import net.fenyo.gnetwatch.targets.*;
031:
032:        import java.io.*;
033:        import java.util.regex.Matcher;
034:        import java.util.regex.Pattern;
035:
036:        import org.apache.commons.logging.Log;
037:        import org.apache.commons.logging.LogFactory;
038:        import org.eclipse.swt.SWT;
039:        import org.eclipse.swt.widgets.MessageBox;
040:
041:        /**
042:         * Instances of this action class use NMAP to explore their target
043:         * and create events of type EventReachable.
044:         * @author Alexandre Fenyo
045:         * @version $Id: ActionNmap.java,v 1.2 2007/03/12 05:04:14 fenyo Exp $
046:         */
047:
048:        // on devrait utiliser l'option -oX file pour traiter l'output en XML...
049:        public class ActionNmap extends Action {
050:            private static Log log = LogFactory.getLog(ActionNmap.class);
051:
052:            // main, Background & Queue threads
053:            // supports any thread
054:            private ExternalCommand cmd_nmap = null;
055:
056:            private String address = "";
057:            private boolean invoked = false;
058:
059:            /**
060:             * Constructor.
061:             * @param target target this action works on.
062:             * @param background queue manager by which this action will add events.
063:             */
064:            // GUI thread
065:            // supports any thread
066:            public ActionNmap(final Target target, final Background background) {
067:                super (target, background);
068:                setItem("nmap");
069:            }
070:
071:            /**
072:             * Constructor.
073:             * @param none.
074:             */
075:            // GUI thread
076:            // supports any thread
077:            public ActionNmap() {
078:                setItem("nmap");
079:            }
080:
081:            /**
082:             * Called to inform about the current GUI.
083:             * @param gui current GUI instance.
084:             * @return void.
085:             */
086:            protected void initialize(final GUI gui) {
087:                super .initialize(gui);
088:            }
089:
090:            /**
091:             * Returns the associated target.
092:             * @param none.
093:             * @return Target associated target.
094:             */
095:            // any thread
096:            public String getQueueName() {
097:                return "nmap";
098:            }
099:
100:            /**
101:             * Returns the timeout associated with this action.
102:             * @param none.
103:             * @return long timeout.
104:             */
105:            // any thread
106:            public long getMaxDelay() {
107:                return new Long(getGUI().getConfig()
108:                        .getProperty("nmap.timeout"));
109:            }
110:
111:            /**
112:             * Asks this action to stop rapidely.
113:             * @param cause cause.
114:             * @return void.
115:             * @throws IOException IO exception.
116:             */
117:            // main & Background threads
118:            // supports any thread
119:            public void interrupt(final InterruptCause cause)
120:                    throws IOException {
121:                if (cmd_nmap != null) {
122:                    cmd_nmap.end();
123:                    if (cause == InterruptCause.timeout)
124:                        getGUI().appendConsole(
125:                                getGUI().getConfig().getPattern(
126:                                        "nmap_interrupted", address)
127:                                        + "<BR/>");
128:                }
129:            }
130:
131:            /**
132:             * Computes the signature of the target.
133:             * @param none.
134:             * @return void.
135:             * @throws IOException IO exception.
136:             * @throws InterruptedException exception.
137:             */
138:            // Queue thread
139:            // supports any thread
140:            public void invoke() throws IOException, InterruptedException {
141:                if (isDisposed() == true)
142:                    return;
143:
144:                super .invoke();
145:
146:                if (invoked == true)
147:                    return;
148:                invoked = true;
149:
150:                try {
151:                    final String[] cmdLine;
152:
153:                    if (TargetIPv4.class.isInstance(getTarget())) {
154:                        final TargetIPv4 target = (TargetIPv4) getTarget();
155:                        address = target.getAddress().toString();
156:                        address = address.substring(1 + address.indexOf('/'));
157:                        cmdLine = new String[] { "nmap", "-A", address };
158:                    } else if (TargetIPv6.class.isInstance(getTarget())) {
159:                        final TargetIPv6 target = (TargetIPv6) getTarget();
160:                        address = target.getAddress().toString();
161:                        address = address.substring(1 + address.indexOf('/'));
162:                        cmdLine = new String[] { "nmap", "-6", "-A", address };
163:                    } else
164:                        return;
165:
166:                    String cmd_line = "";
167:                    for (final String part : cmdLine)
168:                        cmd_line += part + " ";
169:                    getGUI().setStatus(
170:                            getGUI().getConfig()
171:                                    .getPattern("forking", cmd_line));
172:
173:                    cmd_nmap = new ExternalCommand(cmdLine, true);
174:                    try {
175:                        cmd_nmap.fork();
176:                    } catch (final IOException ex) {
177:                        getGUI().asyncExecIfNeeded(new Runnable() {
178:                            public void run() {
179:                                final MessageBox dialog = new MessageBox(
180:                                        getGUI().getShell(), SWT.ICON_ERROR
181:                                                | SWT.OK);
182:                                dialog.setText(getGUI().getConfig().getString(
183:                                        "nmap_error"));
184:                                dialog.setMessage(getGUI().getConfig()
185:                                        .getString("nmap_error_long"));
186:                                dialog.open();
187:                            }
188:                        });
189:
190:                        throw ex;
191:                    }
192:
193:                    final String cmd_output = cmd_nmap.readStdout();
194:                    cmd_nmap.end();
195:
196:                    final Matcher match = Pattern.compile(
197:                            "(\r|\n)Running: (.*)").matcher(cmd_output);
198:                    if (match.find() == true)
199:                        if (match.group(2) != null)
200:                            getParents().get(0).setType(match.group(2));
201:                    getTarget().addEvent(new EventNmap(cmd_output));
202:
203:                } finally {
204:                    getGUI().asyncExecIfNeeded(new Runnable() {
205:                        public void run() {
206:                            synchronized (getGUI().sync_tree) {
207:                                removeVisualElements(getParents().get(0));
208:                            }
209:                        }
210:                    });
211:                }
212:            }
213:
214:            /**
215:             * Called when this element is being removed.
216:             * @param none.
217:             * @return void.
218:             */
219:            protected void disposed() {
220:                // remove us from the action queue
221:                super .disposed();
222:
223:                // interrupt if currently running
224:                try {
225:                    interrupt(InterruptCause.removed);
226:                } catch (final IOException ex) {
227:                    log.error("Exception", ex);
228:                }
229:            }
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.