Skip to content

Commit 8b82702

Browse files
Initial commit
1 parent f1f8aa0 commit 8b82702

36 files changed

+1260
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target/
2+
/.classpath
3+
/.project
4+
/.settings/

pom.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>de.martinspielmann.nmapxmlparser</groupId>
4+
<artifactId>nmapxmlparser</artifactId>
5+
<version>0.9.0-SNAPSHOT</version>
6+
<name>nmapxmlparser</name>
7+
<description>Dependency free Java library to parse nmap xml output into POJO</description>
8+
<properties>
9+
<maven.compiler.release>17</maven.compiler.release>
10+
</properties>
11+
<dependencies>
12+
<dependency>
13+
<groupId>org.junit.jupiter</groupId>
14+
<artifactId>junit-jupiter-engine</artifactId>
15+
<version>5.8.1</version>
16+
<scope>test</scope>
17+
</dependency>
18+
</dependencies>
19+
<build>
20+
<plugins>
21+
<plugin>
22+
<groupId>org.apache.maven.plugins</groupId>
23+
<artifactId>maven-compiler-plugin</artifactId>
24+
<version>3.8.0</version>
25+
<configuration>
26+
<release>${maven.compiler.release}</release>
27+
</configuration>
28+
</plugin>
29+
</plugins>
30+
</build>
31+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.martinspielmnann.nmapxmlparser;
2+
3+
public class NmapParserException extends Exception {
4+
5+
private static final long serialVersionUID = 1L;
6+
7+
public NmapParserException() {
8+
super();
9+
}
10+
11+
public NmapParserException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
12+
super(message, cause, enableSuppression, writableStackTrace);
13+
}
14+
15+
public NmapParserException(String message, Throwable cause) {
16+
super(message, cause);
17+
}
18+
19+
public NmapParserException(String message) {
20+
super(message);
21+
}
22+
23+
public NmapParserException(Throwable cause) {
24+
super(cause);
25+
}
26+
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package de.martinspielmnann.nmapxmlparser;
2+
3+
import java.io.IOException;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
7+
import javax.xml.parsers.ParserConfigurationException;
8+
9+
import org.xml.sax.SAXException;
10+
11+
import de.martinspielmnann.nmapxmlparser.elements.NmapRun;
12+
import de.martinspielmnann.nmapxmlparser.internal.XmlParser;
13+
14+
public class NmapXmlParser {
15+
16+
public NmapRun parse(Path pathToXml) throws IOException, NmapParserException {
17+
return parse(Files.readString(pathToXml));
18+
}
19+
20+
public NmapRun parse(String xmlAsString) throws NmapParserException {
21+
try {
22+
return XmlParser.parse(xmlAsString);
23+
} catch (ParserConfigurationException | SAXException | IOException e) {
24+
throw new NmapParserException(String.format("Error parsing [%s]", xmlAsString), e);
25+
}
26+
}
27+
28+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package de.martinspielmnann.nmapxmlparser.elements;
2+
3+
public record Address(String addr, String addrType) {
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package de.martinspielmnann.nmapxmlparser.elements;
2+
3+
public record Debugging(String level) {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package de.martinspielmnann.nmapxmlparser.elements;
2+
3+
public record ExtraPorts(String filtered, Long count, ExtraReasons extraReasons) {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package de.martinspielmnann.nmapxmlparser.elements;
2+
3+
public record ExtraReasons(String reason, Long count, String proto, String ports) {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package de.martinspielmnann.nmapxmlparser.elements;
2+
3+
public record Finished(Long time, String timeStr, String summary, String elapsed, String exit) {
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package de.martinspielmnann.nmapxmlparser.elements;
2+
3+
public record Host(String startTime, String endTime, Status status, Address address, HostNames hostNames, Ports ports,
4+
OS os, Uptime uptime, TcpSequence tcpSequence, IpIdSequence ipIdSequence, TcpTsSequence tcpTsSequence,
5+
Times times) {
6+
}
7+

0 commit comments

Comments
 (0)