I want to find a list of servers present in a local network using java. Is that possible? Or is there any way to differentiate servers from host machine when doing network scan?
I am not aware of there being a clear distinction between a "normal host" and a "server". The systems I use all operate BOTH as "normal hosts" AND as "servers" ... depending on your perspective. (And you certainly can't distinguish typical systems based on the OS that they run. My laptop runs Linux, for example.)
If (hypothetically) you can come up with some objective criteria for distinguishing the two kinds of system (based on how they behave / respond to network requests), then it would be possible to tell them apart using a tool like nmap. Another option would be to use a tool like OpenVAS
which can make an "educated guess" at a system's OS based on various clues.
But it really comes down to you providing some objective / measurable criteria for deciding if a system is a server.
But nmap just tries to guess the host machines OS and most of the time it failed to guess.
Well yes. Do you expect a typical OS to give away that kind of information to anyone / anything on the network that asks?
Now back in the 1980's ... before the Morris Worm was released into the wild ... people were a lot more trusting. But not in 2018!