Implement first part of command line interface
This commit is contained in:
parent
cdb36b39d2
commit
63a96e6ae6
6
pom.xml
6
pom.xml
|
@ -54,6 +54,12 @@
|
||||||
<artifactId>gremlin-core</artifactId>
|
<artifactId>gremlin-core</artifactId>
|
||||||
<version>3.2.3</version>
|
<version>3.2.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-cli</groupId>
|
||||||
|
<artifactId>commons-cli</artifactId>
|
||||||
|
<version>1.3.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
package de.hsh.inform.orientdb_project;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
import org.apache.commons.cli.CommandLineParser;
|
||||||
|
import org.apache.commons.cli.DefaultParser;
|
||||||
|
import org.apache.commons.cli.HelpFormatter;
|
||||||
|
import org.apache.commons.cli.Options;
|
||||||
|
import org.apache.commons.cli.ParseException;
|
||||||
|
|
||||||
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
|
|
||||||
|
import de.hsh.inform.orientdb_project.model.EthernetFrameModel;
|
||||||
|
import de.hsh.inform.orientdb_project.model.Model;
|
||||||
|
import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService;
|
||||||
|
import de.hsh.inform.orientdb_project.repository.EthernetFrameRepository;
|
||||||
|
import de.hsh.inform.orientdb_project.repository.HostRepository;
|
||||||
|
import de.hsh.inform.orientdb_project.repository.TcpConnectionRepository;
|
||||||
|
|
||||||
|
public class CommandLineInterface {
|
||||||
|
private static final Logger log = Logger.getLogger(CommandLineInterface.class.getName());
|
||||||
|
private Options options = new Options();
|
||||||
|
|
||||||
|
private OrientDbHelperService odhs;
|
||||||
|
|
||||||
|
private OrientGraphNoTx ogf;
|
||||||
|
|
||||||
|
private TcpConnectionRepository tcpConnectionRepository;
|
||||||
|
private HostRepository hostRepository;
|
||||||
|
private EthernetFrameRepository ethernetFrameRepository;
|
||||||
|
|
||||||
|
private boolean keepGoing;
|
||||||
|
|
||||||
|
public CommandLineInterface(OrientDbHelperService odhs) {
|
||||||
|
this.odhs = odhs;
|
||||||
|
this.ogf = odhs.getOrientGraphNoTx();
|
||||||
|
this.tcpConnectionRepository = new TcpConnectionRepository(this.ogf);
|
||||||
|
this.hostRepository = new HostRepository(this.ogf);
|
||||||
|
this.ethernetFrameRepository = new EthernetFrameRepository(this.odhs.getDatabaseDocument());
|
||||||
|
|
||||||
|
options.addOption("e", "ethernetFramesByBytes", false, "Find ethernet frames that contain a given byte sequence.");
|
||||||
|
|
||||||
|
options.addOption("htoipp", "hostsByIpAndPort", false, "Find hosts that have tcp connections to a given ip address and port.");
|
||||||
|
options.addOption("htoex", "hostsByConnToExternalHosts", false, "Find hosts that have tcp connections to external hosts.");
|
||||||
|
options.addOption("hinw", "hostsWithIncomingOnWellKnownPorts", false, "Find hosts that have incoming tcp connections on well known ports.");
|
||||||
|
|
||||||
|
options.addOption("ta", "tcpConnectionActiveAt", false, "Find tcp connections that were active at a given timestamp.");
|
||||||
|
options.addOption("tbpm", "tcpConnectionBytesPerMinuteBetween", false, "Get datavolume (bytes per minute) between two given ip addresses.");
|
||||||
|
|
||||||
|
options.addOption("h", "help", false, "show help.");
|
||||||
|
options.addOption("q", "quit", false, "quit the program.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void parse(String arguments) {
|
||||||
|
String[] args = arguments.split(" ");
|
||||||
|
CommandLineParser parser = new DefaultParser();
|
||||||
|
CommandLine cmd = null;
|
||||||
|
try {
|
||||||
|
cmd = parser.parse(options, args);
|
||||||
|
if(cmd.hasOption("h"))
|
||||||
|
this.help();
|
||||||
|
if(cmd.hasOption("q"))
|
||||||
|
this.quit();
|
||||||
|
|
||||||
|
if(cmd.hasOption("e")) {
|
||||||
|
String allBytes = "";
|
||||||
|
for(String byteValue : cmd.getArgs()) {
|
||||||
|
allBytes += byteValue;
|
||||||
|
}
|
||||||
|
byte[] needle = new BigInteger(allBytes, 16).toByteArray();
|
||||||
|
|
||||||
|
List<EthernetFrameModel> result = this.ethernetFrameRepository.findAllByRawData(needle);
|
||||||
|
System.out.println("EthernetFrames that contain the given bytes:");
|
||||||
|
this.printResults(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cmd.hasOption("htoipp")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
//log.log(Level.SEVERE, "Failed to parse comand line properties", e);
|
||||||
|
log.log(Level.SEVERE, "I did not understand that. Sorry.");
|
||||||
|
this.help();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printResults(List<? extends Model> result) {
|
||||||
|
for(Object o : result) {
|
||||||
|
System.out.println(o);
|
||||||
|
}
|
||||||
|
System.out.println("End of result list.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void quit() {
|
||||||
|
this.keepGoing = false;
|
||||||
|
System.out.println("Bye bye.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void help() {
|
||||||
|
HelpFormatter formater = new HelpFormatter();
|
||||||
|
formater.printHelp(" ", options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
this.keepGoing = true;
|
||||||
|
Scanner s = new Scanner(System.in);
|
||||||
|
while(this.keepGoing) {
|
||||||
|
System.out.print("> ");
|
||||||
|
String arguments = s.nextLine();
|
||||||
|
System.out.println("");
|
||||||
|
this.parse(arguments);
|
||||||
|
}
|
||||||
|
System.out.println("End of Program");
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,16 +1,8 @@
|
||||||
package de.hsh.inform.orientdb_project;
|
package de.hsh.inform.orientdb_project;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
|
|
||||||
import de.hsh.inform.orientdb_project.model.EthernetFrameModel;
|
|
||||||
import de.hsh.inform.orientdb_project.model.HostModel;
|
|
||||||
import de.hsh.inform.orientdb_project.model.TcpConnectionModel;
|
|
||||||
import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService;
|
import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService;
|
||||||
import de.hsh.inform.orientdb_project.repository.EthernetFrameRepository;
|
|
||||||
import de.hsh.inform.orientdb_project.repository.HostRepository;
|
|
||||||
import de.hsh.inform.orientdb_project.repository.TcpConnectionRepository;
|
|
||||||
import de.hsh.inform.orientdb_project.util.ConfigPropertiesReader;
|
import de.hsh.inform.orientdb_project.util.ConfigPropertiesReader;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
@ -22,8 +14,12 @@ public class Main {
|
||||||
System.out.println("Using database: " + odhs.getDbUri(true));
|
System.out.println("Using database: " + odhs.getDbUri(true));
|
||||||
|
|
||||||
// Get "handle" for database to pass to import service
|
// Get "handle" for database to pass to import service
|
||||||
OrientGraphNoTx ogf = odhs.getOrientGraphNoTx();
|
//OrientGraphNoTx ogf = odhs.getOrientGraphNoTx();
|
||||||
|
|
||||||
|
CommandLineInterface cli = new CommandLineInterface(odhs);
|
||||||
|
cli.run();
|
||||||
|
|
||||||
|
/*
|
||||||
TcpConnectionRepository tcr = new TcpConnectionRepository(ogf);
|
TcpConnectionRepository tcr = new TcpConnectionRepository(ogf);
|
||||||
List<TcpConnectionModel> result = tcr.findByActiveWhen(901713642);
|
List<TcpConnectionModel> result = tcr.findByActiveWhen(901713642);
|
||||||
for(TcpConnectionModel m : result) {
|
for(TcpConnectionModel m : result) {
|
||||||
|
@ -49,6 +45,7 @@ public class Main {
|
||||||
for(EthernetFrameModel em : efrbyteResult) {
|
for(EthernetFrameModel em : efrbyteResult) {
|
||||||
System.out.println(em);
|
System.out.println(em);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
odhs.close();
|
odhs.close();
|
||||||
|
|
|
@ -7,7 +7,7 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
|
|
||||||
// TODO: Not finished?
|
// TODO: Not finished?
|
||||||
public class ArpPacketModel {
|
public class ArpPacketModel implements Model {
|
||||||
|
|
||||||
public long ts;
|
public long ts;
|
||||||
public int ms;
|
public int ms;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import com.tinkerpop.blueprints.Vertex;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
|
|
||||||
public class EthernetFrameModel {
|
public class EthernetFrameModel implements Model {
|
||||||
|
|
||||||
public long ts;
|
public long ts;
|
||||||
public int ms;
|
public int ms;
|
||||||
|
|
|
@ -5,7 +5,7 @@ import com.tinkerpop.blueprints.Vertex;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
|
|
||||||
public class HostModel {
|
public class HostModel implements Model {
|
||||||
|
|
||||||
public String ipAddress;
|
public String ipAddress;
|
||||||
public boolean internal;
|
public boolean internal;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
|
|
||||||
public class IcmpPacketModel {
|
public class IcmpPacketModel implements Model {
|
||||||
|
|
||||||
public long ts;
|
public long ts;
|
||||||
public int ms;
|
public int ms;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
|
|
||||||
public class IpPacketModel {
|
public class IpPacketModel implements Model {
|
||||||
|
|
||||||
public long ts;
|
public long ts;
|
||||||
public int ms;
|
public int ms;
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package de.hsh.inform.orientdb_project.model;
|
||||||
|
|
||||||
|
public interface Model {
|
||||||
|
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
|
|
||||||
|
|
||||||
public class TcpConnectionModel {
|
public class TcpConnectionModel implements Model {
|
||||||
|
|
||||||
public long startTs;
|
public long startTs;
|
||||||
public int startMs;
|
public int startMs;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
|
|
||||||
public class TcpPacketModel {
|
public class TcpPacketModel implements Model {
|
||||||
|
|
||||||
public long ts;
|
public long ts;
|
||||||
public int ms;
|
public int ms;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
|
|
||||||
public class UdpPacketModel {
|
public class UdpPacketModel implements Model {
|
||||||
|
|
||||||
public long ts;
|
public long ts;
|
||||||
public int ms;
|
public int ms;
|
||||||
|
|
|
@ -4,7 +4,7 @@ import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
|
|
||||||
public class WellKnownPortModel {
|
public class WellKnownPortModel implements Model {
|
||||||
|
|
||||||
public int port;
|
public int port;
|
||||||
public String description;
|
public String description;
|
||||||
|
|
Loading…
Reference in New Issue