added host name support
This commit is contained in:
@ -9,17 +9,19 @@ import java.util.concurrent.Executors;
|
|||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author joern.muehlencord
|
* @author joern.muehlencord
|
||||||
*/
|
*/
|
||||||
public class PortScanner {
|
public class PortScanner {
|
||||||
|
|
||||||
private final static Logger LOGGER = LoggerFactory.getLogger(PortScanner.class);
|
private final static Logger LOGGER = LoggerFactory.getLogger(PortScanner.class);
|
||||||
|
|
||||||
private final int startPort;
|
private final int startPort;
|
||||||
private final int endPort;
|
private final int endPort;
|
||||||
private final int timeout;
|
private final int timeout;
|
||||||
|
private String host = null;
|
||||||
|
|
||||||
public PortScanner(int timeoutInMs, int startPort, int endPort) {
|
public PortScanner(int timeoutInMs, int startPort, int endPort) {
|
||||||
this.startPort = startPort;
|
this.startPort = startPort;
|
||||||
@ -32,6 +34,7 @@ public class PortScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<PortInformation> scan(String ip) {
|
public List<PortInformation> scan(String ip) {
|
||||||
|
this.host = ip;
|
||||||
|
|
||||||
final List<PortInformation> resultList = new ArrayList<>();
|
final List<PortInformation> resultList = new ArrayList<>();
|
||||||
final ExecutorService es = Executors.newFixedThreadPool(20);
|
final ExecutorService es = Executors.newFixedThreadPool(20);
|
||||||
@ -42,7 +45,7 @@ public class PortScanner {
|
|||||||
es.shutdown();
|
es.shutdown();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (final Future<PortInformation> f : futures) {
|
for (final Future<PortInformation> f : futures) {
|
||||||
resultList.add(f.get());
|
resultList.add(f.get());
|
||||||
}
|
}
|
||||||
} catch (InterruptedException | ExecutionException ex) {
|
} catch (InterruptedException | ExecutionException ex) {
|
||||||
@ -53,6 +56,10 @@ public class PortScanner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* *** getter *** */
|
/* *** getter *** */
|
||||||
|
public String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStartPort() {
|
public int getStartPort() {
|
||||||
return startPort;
|
return startPort;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user