mirror of
https://github.com/angryip/ipscan.git
synced 2025-10-26 11:18:17 +00:00
First bits of command-line support
git-svn-id: https://ipscan.svn.sourceforge.net/svnroot/ipscan/trunk@430 375186e5-ef17-0410-b0b6-91563547dcda
This commit is contained in:
parent
28cde64024
commit
ae3c028f4c
@ -10,6 +10,7 @@ import java.util.Locale;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.azib.ipscan.config.CommandLineProcessor;
|
||||
import net.azib.ipscan.config.ComponentRegistry;
|
||||
import net.azib.ipscan.config.Config;
|
||||
import net.azib.ipscan.config.Labels;
|
||||
@ -54,8 +55,6 @@ public class Main {
|
||||
|
||||
initSystemProperties();
|
||||
|
||||
processCommandLine(args);
|
||||
|
||||
Display display = Display.getDefault();
|
||||
LOG.finer("SWT initialized after " + (System.currentTimeMillis() - startTime));
|
||||
|
||||
@ -68,8 +67,10 @@ public class Main {
|
||||
ComponentRegistry componentRegistry = new ComponentRegistry();
|
||||
LOG.finer("ComponentRegistry initialized after " + (System.currentTimeMillis() - startTime));
|
||||
|
||||
processCommandLine(args, componentRegistry);
|
||||
|
||||
// create the main window using dependency injection
|
||||
MainWindow mainWindow = componentRegistry.createMainWindow();
|
||||
MainWindow mainWindow = componentRegistry.getMainWindow();
|
||||
LOG.fine("Startup time: " + (System.currentTimeMillis() - startTime));
|
||||
|
||||
while (!mainWindow.isDisposed()) {
|
||||
@ -109,12 +110,11 @@ public class Main {
|
||||
Security.setProperty("networkaddress.cache.negative.ttl", "0");
|
||||
}
|
||||
|
||||
private static void processCommandLine(String[] args) {
|
||||
private static void processCommandLine(String[] args, ComponentRegistry componentRegistry) {
|
||||
if (args.length != 0) {
|
||||
// TODO: implement command-line
|
||||
String usageText = "Command-line usage is not implemented yet, sorry";
|
||||
|
||||
showMessageToConsole(usageText);
|
||||
CommandLineProcessor cli = componentRegistry.getCommandLineProcessor();
|
||||
showMessageToConsole(cli.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,7 +131,6 @@ public class Main {
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Java 5 will reach here
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (haveConsole) {
|
||||
|
||||
38
src/net/azib/ipscan/config/CommandLineProcessor.java
Normal file
38
src/net/azib/ipscan/config/CommandLineProcessor.java
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* This file is a part of Angry IP Scanner source code,
|
||||
* see http://www.azib.net/ for more information.
|
||||
* Licensed under GPLv2.
|
||||
*/
|
||||
|
||||
package net.azib.ipscan.config;
|
||||
|
||||
import net.azib.ipscan.exporters.ExporterRegistry;
|
||||
import net.azib.ipscan.feeders.Feeder;
|
||||
import net.azib.ipscan.gui.feeders.AbstractFeederGUI;
|
||||
|
||||
/**
|
||||
* CommandLineProcessor
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public class CommandLineProcessor {
|
||||
|
||||
private AbstractFeederGUI[] feeders;
|
||||
private ExporterRegistry exporters;
|
||||
|
||||
public CommandLineProcessor(AbstractFeederGUI[] feeders, ExporterRegistry exporters) {
|
||||
this.feeders = feeders;
|
||||
this.exporters = exporters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder usage = new StringBuilder();
|
||||
usage.append("Command-line support is not yet implemented...\n\nAvailable feeders:\n");
|
||||
for (AbstractFeederGUI feeder : feeders) {
|
||||
usage.append(feeder.getFeederName()).append('\n');
|
||||
}
|
||||
return usage.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@ -72,6 +72,7 @@ import org.picocontainer.defaults.DefaultPicoContainer;
|
||||
public class ComponentRegistry {
|
||||
|
||||
private PicoContainer container;
|
||||
private boolean containerStarted;
|
||||
|
||||
public ComponentRegistry() {
|
||||
MutablePicoContainer container = new DefaultPicoContainer();
|
||||
@ -113,6 +114,7 @@ public class ComponentRegistry {
|
||||
container.registerComponentImplementation(Scanner.class);
|
||||
container.registerComponentImplementation(StateMachine.class);
|
||||
container.registerComponentImplementation(ScannerDispatcherThreadFactory.class);
|
||||
container.registerComponentImplementation(CommandLineProcessor.class);
|
||||
|
||||
// GUI follows (TODO: move GUI to a separate place)
|
||||
|
||||
@ -211,11 +213,23 @@ public class ComponentRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindow createMainWindow() {
|
||||
private void start() {
|
||||
if (!containerStarted) {
|
||||
containerStarted = true;
|
||||
container.start();
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindow getMainWindow() {
|
||||
// initialize all startable components
|
||||
container.start();
|
||||
start();
|
||||
// initialize and return the main window
|
||||
return (MainWindow) container.getComponentInstance(MainWindow.class);
|
||||
}
|
||||
|
||||
public CommandLineProcessor getCommandLineProcessor() {
|
||||
start();
|
||||
return (CommandLineProcessor) container.getComponentInstance(CommandLineProcessor.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
41
src/net/azib/ipscan/exporters/SQLExporter.java
Normal file
41
src/net/azib/ipscan/exporters/SQLExporter.java
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package net.azib.ipscan.exporters;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.azib.ipscan.config.Labels;
|
||||
import net.azib.ipscan.core.PortIterator;
|
||||
import net.azib.ipscan.core.values.NumericRangeList;
|
||||
import net.azib.ipscan.fetchers.IPFetcher;
|
||||
import net.azib.ipscan.fetchers.PortsFetcher;
|
||||
|
||||
/**
|
||||
* SQL Exporter
|
||||
* <p/>
|
||||
* Exports results as an SQL inserts, suitable for sqlite, mysql, etc,
|
||||
* optionally preceding by a 'create table'.
|
||||
* TODO: implement SQLExporter
|
||||
*
|
||||
* @author Anton Keks
|
||||
*/
|
||||
public class SQLExporter extends AbstractExporter {
|
||||
|
||||
static final char DELIMETER = ':';
|
||||
|
||||
public String getId() {
|
||||
return "exporter.sql";
|
||||
}
|
||||
|
||||
public String getFilenameExtension() {
|
||||
return "sql";
|
||||
}
|
||||
|
||||
public void setFetchers(String[] fetcherNames) throws IOException {
|
||||
}
|
||||
|
||||
public void nextAdressResults(Object[] results) throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user