Skip to content

Commit

Permalink
Fix issue reading host names in network location list.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwright324 committed Aug 16, 2017
1 parent e3b1770 commit 1131bd2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ Configuration will only affect network scanning and not drive discovery on the l
* LocalAdmin:123456
* NetworkAdmin:21345|localdomain

**Network Locations** are listed in single IP, network range, or CIDR formats. Acceptable examples:
**Network Locations** are listed in single IP, single name, network range, or CIDR formats. Acceptable examples:
* 192.168.1.1
* 192.355.2.1 // Overflowing segments greater than 255 are added onto the next (left) number. Converts to '193.99.2.1'
* 192.168.1.0-192.168.1.255
* 192.168.1.0/18
* 192.168.1.0/18
* neptune-04.localdomain.com
* local-system-name
34 changes: 20 additions & 14 deletions src/mattw/jexplorer/JExplorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.ArrayList;
Expand Down Expand Up @@ -377,26 +378,31 @@ private List<Object> parseNetworkLocations(String locations) {
for(String s : Arrays.asList(locations.split("\n"))) {
if(!s.startsWith("#")) {
try {
if(s.contains("-") || s.contains("/")) {
if(s.contains("/") && AddressBlock.isCIDR(s)) {
block = new AddressBlock(s);
} else if(s.contains("-")) {
String[] parts = s.split("-");
if(parts.length == 2) {
block = new AddressBlock(new Address(parts[0].trim()), new Address(parts[1].trim()));
locs.add(InetAddress.getByName(s).getHostAddress());
} catch (Exception ignored) {
try {
if(s.contains("-") || s.contains("/")) {
if(s.contains("/") && AddressBlock.isCIDR(s)) {
block = new AddressBlock(s);
} else if(s.contains("-")) {
String[] parts = s.split("-");
if(parts.length == 2) {
block = new AddressBlock(new Address(parts[0].trim()), new Address(parts[1].trim()));
}
}
if(block != null) {
locs.add(block);
}
} else {
locs.add(s);
}
if(block != null) {
locs.add(block);
}
} else {
locs.add(s);
} catch (Exception e) {
System.err.println(s);
}
} catch (Exception e) {
System.err.println(s);
}
}
}
System.out.println(locs);
return locs;
}

Expand Down

0 comments on commit 1131bd2

Please sign in to comment.