added port scanner support
This commit is contained in:
@ -0,0 +1,30 @@
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import org.apache.commons.net.util.SubnetUtils;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
public class NetworkScannerTest {
|
||||
|
||||
public NetworkScannerTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScan() throws UnknownHostException {
|
||||
String ipAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
SubnetUtils utils = new SubnetUtils(ipAddress, "255.255.255.0");
|
||||
String networkAddress = utils.getInfo().getNetworkAddress();
|
||||
|
||||
NetworkScanner networkScanner = new NetworkScanner (networkAddress+"/24"); // TODO get ip address from network device
|
||||
networkScanner.scan();
|
||||
assertFalse (networkScanner.getIpsInNetwork().isEmpty());
|
||||
System.out.println (networkScanner.getIpsInNetwork());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package de.muehlencord.shared.network;
|
||||
|
||||
import java.util.List;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
public class PortScannerTest {
|
||||
|
||||
public PortScannerTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMain() {
|
||||
PortScanner portScanner = new PortScanner();
|
||||
List<PortInformation> resultList = portScanner.scan("127.0.0.1");
|
||||
|
||||
int openPorts = 0;
|
||||
for (PortInformation result : resultList) {
|
||||
if (result.isOpen()) {
|
||||
System.out.println("Port " + result.getPortNumber() + " is open");
|
||||
openPorts++;
|
||||
}
|
||||
}
|
||||
System.out.println("There are " + openPorts + " open ports on host " + portScanner.getTimeout() + " (probed with a timeout of "
|
||||
+ portScanner.getTimeout() + "ms)");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,8 +2,11 @@
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
package de.muehlencord.shared.network.whois;
|
||||
|
||||
import de.muehlencord.shared.network.BaseTest;
|
||||
import de.muehlencord.shared.network.whois.WhoisInformation;
|
||||
import de.muehlencord.shared.network.whois.WhoisException;
|
||||
import java.io.IOException;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
@ -2,8 +2,12 @@
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package de.muehlencord.shared.network;
|
||||
package de.muehlencord.shared.network.whois;
|
||||
|
||||
import de.muehlencord.shared.network.BaseTest;
|
||||
import de.muehlencord.shared.network.whois.Whois;
|
||||
import de.muehlencord.shared.network.whois.WhoisInformation;
|
||||
import de.muehlencord.shared.network.whois.WhoisException;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
Reference in New Issue
Block a user