[...]
I have been thinking about this, I haven't written the code yet but
something like:
for( i = 1; i < 255; i++ )
{
IPaddress = string.format("192.168.1.{0}", i )
connect to your specific port, eg ssh
if( connect ok )
list.add( IPaddress );
disconnect.
}
As far as pseudo-code goes, I guess that's fine. However, note that the
above code will be extremely slow on a sparsely populated network,
because every connection attempt that fails won't do so until a
several-second timeout occurs.
The OP hasn't provided any more details about his problem. Not about
what protocols the devices support or respond to, nor about what level of
network programming experience he has, or even the exact nature of his
question. Speaking hypothetically though, the ideal situation would be
network devices that respond in a unique, well-defined way to a UDP
broadcast. Then the querying computer could just broadcast a message
asking for relevant devices to respond. Optimizations to the protocol
could be made to deal with network congestion issues, if having every
device respond to a single query results in some of those responses being
lost.
If indeed a TCP connection to each device is required, then rather than a
serialized enumeration of each IP address, I would use the asynchronous
pattern for the Socket class (or TcpClient, according to one's
preference), so that failed connections don't slow down detection of the
successful ones. It would require up to 254 sockets to exist
simultaneously, which is not a problem at all.
But, who knows whether any of this is useful to the OP at all. Unless he
comes back and continues the thread, we're just shooting in the dark.
Pete