added port scanner support

This commit is contained in:
jomu
2014-07-10 10:02:42 +00:00
parent d19fe07b6f
commit dc1a947ad8
20 changed files with 365 additions and 28 deletions

View File

@ -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());
}
}

View File

@ -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)");
}
}

View File

@ -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.*;

View File

@ -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.*;