views:

31

answers:

1

Hi. This is more a logical thinking issue rather than coding. I already have some working code blocks - one which telnets to a device, one which parses results of a command, one which populates a dictionary etc etc

Now lets say I want to analyse a network with unknown nodes, a,b,c etc (but I only know about 1)

I give my code block node a. The results are a table including b, c. I save that in a dictionary

I then want to use that first entry (b) as a target and see what it can see. Possibly d, e, etc And add those (if any) to the dict

And then do the same on the next node in this newly populated dictionary. The final output would be that all nodes have been visited once only, and all devices seen are recorded in this (or another) dictionary.

However I can't figure out how to keep re-reading the dict as it grows, and I can't figure out how to avoid looking at a device more than once.

I understand this is clearer to me than I have explained, apologies if it's confusing

+2  A: 

You are looking at graph algorithms, specifically DFS or BFS. Are you asking specifically about implementation details, or more generally about the algorithms?

Recursion would be a very neat way of doing this.

seen = {}
def DFS( node ):
    for neighbour in node.neighbours():
        if neighbour not in seen:
            seen[ neighbour ] = some_info_about_neighbour
            DFS( neighbour )
katrielalex