Skip to content

Commit 421bd6c

Browse files
committed
Merge branch 'release-0.4' - Added graph view to master
2 parents fb23f5d + 87ce60c commit 421bd6c

File tree

23 files changed

+1410
-38
lines changed

23 files changed

+1410
-38
lines changed

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ addons:
77
apt:
88
packages:
99
- nmap
10-
10+
11+
before_script:
12+
- "export DISPLAY=:99.0"
13+
- "sh -e /etc/init.d/xvfb start"
14+
- sleep 3
15+
1116
before_install:
1217
- pip install --user codecov
1318

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ If you have any questions about NMapGUI usage or want to get in contact with me,
1818
* Multiple command execution at the same time.
1919
* Standard NMap output.
2020
* HTML report NMap output.
21+
* Interactive traceroute graph output
2122
* Saving output as XML.
2223
* Output minimizing, maximizing and deleting.
2324
* Menu to find most of nmap options.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.uniovi.nmapgui</groupId>
77
<artifactId>nmapGUI</artifactId>
8-
<version>0.3.1-SNAPSHOT</version>
8+
<version>0.4-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

1111
<name>NMapGUI</name>

src/main/java/com/uniovi/nmapgui/NMapLoaderWindow.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class NMapLoaderWindow extends JFrame {
3737
private static final String IMG_PATH = "static/img/header.jpg";
3838

3939

40-
private JLabel image;
4140
private JButton start;
4241
private JButton stop;
4342
private ConfigurableApplicationContext springContext;
@@ -77,15 +76,15 @@ private JPanel image() {
7776
} catch (IOException e) {
7877
e.printStackTrace();
7978
}
80-
ImageIcon icon = new ImageIcon(img);
81-
image = new JLabel(icon);
82-
image.setLayout(new FlowLayout(FlowLayout.RIGHT));
83-
79+
ImageIcon icon = new ImageIcon(img);
80+
JLabel image = new JLabel(icon);
81+
image.setLayout(new FlowLayout(FlowLayout.RIGHT));
82+
image.setName("image");
8483

85-
go= new JButton("Go!");
86-
go.setEnabled(false);
87-
88-
go.addActionListener(new ActionListener() {
84+
go= new JButton("Go!");
85+
go.setEnabled(false);
86+
go.setName("go");
87+
go.addActionListener(new ActionListener() {
8988
@Override
9089
public void actionPerformed(ActionEvent e) {
9190
try {
@@ -109,6 +108,7 @@ private JPanel buttons() {
109108
gl.setVgap(5);
110109
buttons.setLayout(gl);
111110
start = new JButton("Start NMapGUI");
111+
start.setName("start");
112112
if(!nmapInstalled){
113113
start.setEnabled(false);
114114
start.setText("NMap is not installed");
@@ -129,6 +129,7 @@ public void actionPerformed(ActionEvent e) {
129129
buttons.add(start);
130130

131131
stop = new JButton("Nmap not running");
132+
stop.setName("stop");
132133
stop.addActionListener(new ActionListener() {
133134
@Override
134135
public void actionPerformed(ActionEvent e) {

src/main/java/com/uniovi/nmapgui/executor/CommandExecutor.java

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import java.util.Arrays;
77
import java.util.Date;
88
import java.util.List;
9-
9+
import java.util.regex.Matcher;
10+
import java.util.regex.Pattern;
11+
import javax.xml.bind.JAXBContext;
12+
import javax.xml.bind.Unmarshaller;
1013

1114
import com.uniovi.nmapgui.model.*;
1215
import com.uniovi.nmapgui.util.TransInfoHtml;
@@ -18,23 +21,17 @@ public class CommandExecutor {
1821

1922

2023
public CommandExecutor(Command command) {
24+
this();
2125
cmd=command;
2226
}
2327
public CommandExecutor(){};
2428

2529

2630
public boolean execute(){
27-
String filename= "nmap-scan_" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")
28-
.format(new Date())+ ".xml";
29-
30-
this.cmd.getOutput().setFilename(filename);
31-
tempPath=tempPath + filename;
32-
List<String> commandsList = new ArrayList<String>();
33-
commandsList.add("nmap");
34-
commandsList.addAll(Arrays.asList(cmd.getText().split(" ")));
35-
commandsList.addAll(Arrays.asList(new String[]{"-oX" , getTempPath(), "--webxml"}));
31+
String[] command = composeCommand();
32+
3633
try {
37-
Process p = Runtime.getRuntime().exec(commandsList.toArray(new String[]{}));
34+
Process p = Runtime.getRuntime().exec(command);
3835
final InputStream stream = p.getInputStream();
3936
final InputStream errors = p.getErrorStream();
4037
commandThread = new Thread(new Runnable() {
@@ -43,9 +40,9 @@ public void run() {
4340
BufferedReader errorReader = null;
4441

4542
try {
43+
boolean firstLine=true;
4644
reader = new BufferedReader(new InputStreamReader(stream));
4745
String line = null;
48-
cmd.getOutput().setText("<pre></pre>");
4946
while ((line = reader.readLine()) != null) {
5047
line=escape(line);
5148
if (line.contains( " open "))
@@ -54,13 +51,23 @@ else if (line.contains( " closed "))
5451
line="<span class=\"closed\">"+line+"</span>";
5552
else if (line.contains( " filtered "))
5653
line="<span class=\"filtered\">"+line+"</span>";
57-
cmd.getOutput().setText(cmd.getOutput().getText().replaceAll("</pre>", "\n")+line+"</pre>");
54+
String jump = "\n";
55+
if(firstLine)
56+
jump="";
57+
cmd.getOutput().setText(cmd.getOutput().getText()+jump+line);
58+
firstLine=false;
59+
5860
}
5961
errorReader = new BufferedReader(new InputStreamReader(errors));
6062
while ((line = errorReader.readLine()) != null) {
6163
line=escape(line);
6264
line="<span class=\"closed\">"+line+"</span>";
63-
cmd.getOutput().setText(cmd.getOutput().getText().replaceAll("</pre>", "\n")+"<i>"+line+"</i></pre>");
65+
String jump = "\n";
66+
if(firstLine)
67+
jump="";
68+
cmd.getOutput().setText(cmd.getOutput().getText()+jump+"<i>"+line+"</i>");
69+
firstLine=false;
70+
6471
}
6572

6673
} catch (Exception e) {
@@ -84,6 +91,32 @@ else if (line.contains( " filtered "))
8491
}
8592
return true;
8693
}
94+
95+
private String[] composeCommand() {
96+
97+
String filename= "nmap-scan_" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss")
98+
.format(new Date())+ ".xml";
99+
100+
this.cmd.getOutput().setFilename(filename);
101+
tempPath=tempPath + filename;
102+
List<String> commandList = new ArrayList<String>();
103+
commandList.add("nmap");
104+
commandList.addAll(splitOptions());
105+
commandList.addAll(Arrays.asList(new String[]{"-oX" , getTempPath(), "--webxml"}));
106+
107+
return commandList.toArray(new String[]{});
108+
109+
}
110+
111+
private List<String> splitOptions(){
112+
List<String> options = new ArrayList<>();
113+
//Splits string by spaces other than the ones in substring quotes
114+
Matcher matcher = Pattern.compile("\\s*([^(\"|\')]\\S*|\".+?\"|\'.+?\')\\s*").matcher(cmd.getText());
115+
while (matcher.find())
116+
options.add(matcher.group(1));
117+
118+
return options;
119+
}
87120

88121
private String escape(String str) {
89122
String line=str;
@@ -123,8 +156,13 @@ public void readXML() {
123156
String sCurrentLine;
124157
while ((sCurrentLine = br.readLine()) != null) {
125158
sb.append(sCurrentLine);
126-
}
159+
}
160+
JAXBContext jaxbContext = JAXBContext.newInstance(Scan.class);
161+
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
162+
StringReader reader = new StringReader(sb.toString());
163+
Scan scan = (Scan) unmarshaller.unmarshal(reader);
127164
cmd.getOutput().setXml(TransInfoHtml.transformToHtml(sb.toString()));
165+
cmd.getOutput().setScan(scan);
128166

129167
} catch (Exception e) {
130168
e.printStackTrace();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.uniovi.nmapgui.model;
2+
3+
import javax.xml.bind.annotation.XmlAttribute;
4+
import javax.xml.bind.annotation.XmlRootElement;
5+
6+
@XmlRootElement(name="address")
7+
public class Address {
8+
9+
private String address;
10+
11+
public Address(String address) {
12+
setAddress(address);
13+
}
14+
public Address(){}
15+
16+
@XmlAttribute(name="addr")
17+
public String getAddress() {
18+
return address;
19+
}
20+
21+
public void setAddress(String address) {
22+
this.address = address;
23+
}
24+
25+
@Override
26+
public String toString() {
27+
return "Address [address=" + getAddress() + "]";
28+
}
29+
30+
@Override
31+
public boolean equals(Object obj) {
32+
if (this == obj)
33+
return true;
34+
if (obj == null)
35+
return false;
36+
if (getClass() != obj.getClass())
37+
return false;
38+
Address other = (Address) obj;
39+
if (address == null) {
40+
if (other.address != null)
41+
return false;
42+
} else if (!address.equals(other.address))
43+
return false;
44+
return true;
45+
}
46+
47+
48+
49+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.uniovi.nmapgui.model;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
import javax.xml.bind.annotation.XmlAttribute;
7+
8+
public class Hop {
9+
10+
private String address;
11+
private String host;
12+
13+
@XmlAttribute(name="ipaddr")
14+
public String getAddress() {
15+
return address;
16+
}
17+
18+
public void setAddress(String address) {
19+
this.address = address;
20+
}
21+
22+
@XmlAttribute(name="host")
23+
public String getHost() {
24+
return host;
25+
}
26+
27+
public void setHost(String host) {
28+
this.host = host;
29+
}
30+
31+
@Override
32+
public String toString() {
33+
return "Hop [address=" + getAddress() + ", host=" + getHost() + "]";
34+
}
35+
36+
public Host toHost(){
37+
Host host = new Host();
38+
host.setAddress(new Address(address));
39+
Set<Hostname> set = new HashSet<Hostname>();
40+
if (host!=null)
41+
set.add(new Hostname(this.host));
42+
host.setHostNames(set);
43+
44+
return host;
45+
}
46+
47+
48+
}

0 commit comments

Comments
 (0)