First, you probably want to look at
GD which will enable you to draw the graph that you are talking about. There are a couple of scripts that do network diagrams, and you probably want to look at them as well. Some reinventing of the wheel is a good thing, but too much is a waste of time.
Second, if you want to generate a single map with all of the computers, you are going to need to learn a bit about trees and how to describe the connections between routers. Basically, you'll need to do some sort hash that lists each gateway and describes the gateways that it is connected to, and where on your map you want to place the nodes (gateways). This is definetly non-trivial, so I would start working on it one slice at a time.