I've been trying to create an application which needs to scan open ports on a network (mostly LAN) as fast as possible.
I searched around and one great method that I found uses the following code:
(1 to 65536).par.map { case port ⇒
try {
val socket = new java.net.Socket("127.0.0.1", port)
socket.close()
println(port)
port
} catch {
case _: Throwable ⇒ -1
}
}.toSet
However, the problem with the code is that if I enter anything other than 127.0.0.1 or localhost as location (say 192.168.1.2), the application freezes.
Any idea why this happens and how I can fix it?
P.S. I also tried setting socket timeout with socket.setSoTimeout(1500), but no change.