I did a brief search on libraries that could be useful to solve your problem, so I found a library called ping discover network plus, i haven't tested the library, but from what I understood from your question, it might be useful.