This is very possible, and I could probably adapt some code from one of my (currently untested) hobby projects for this, but first I have some questions:
What, exactly, is the purpose of this program you ask of the Monastery?
Are you trying to determine which "random" port a known program has chosen for a particular session? What program are we trying to extract information from? If this is a protocol that several programs use, does it have a name? What is at least one program using this?
Why is there not some directory we can query for these ephemeral servers? Why do we have to search like this?
What, exactly, do you need done?
Does this need to send a string "$addr:$port status\n" to multiple ports until one answers? Do we expect all other ports to be closed entirely? Is this using TCP or UDP or something else? Are they all on the same host or are we gathering status information from some kind of cluster? Or is a single host "fronting" for some kind of cluster?
This sounds very much like a common system cracker tool, although there are legitimate uses for this type of functionality as well. I want to be sure that you have a legitimate use before I even think about giving you code for this.
Answering all of these questions will go a long way towards establishing your legitimacy. Having worked in systems administration at a small Internet-dependent business, where kicking script kiddies out of the aging PHP-heavy infrastructure that management did not want to upgrade was a large part of my job, I have no desire to help that kind of nonsense along.