I have created a port scanner with multi-threading that scans ports, starting at 1 and going up in numbers. It works great on my LAN but if I try to scan an IP outside of my LAN it says all ports are closed, which I assume is because the firewall is blocking the connection?
Is there any way to check if the port is open on an IP address outside my LAN? This is the code I've got
for (int port = startPort; port < 65535; port+=PortScanner.count)
{
Socket socket;
try
{
socket = new Socket();
socket.connect(new InetSocketAddress(host, port ), 500);
openPorts.add(port);
foundPort = true;
String temp = "Port " + port + " is open.\n";
System.out.write(temp.getBytes());
socket.close();
}
catch (IOException ioEx)
{
System.out.println("Port " + port + " is closed");
}
}
Thread.yield();