However, if you want to limit also the time for reading the inputstream without throwing an exception, then you need a costum solution: Is it possible to read from a InputStream with a timeout?
The following running example worked very well in my local network. It tried to connect for at most three seconds and detected all running webservers.