We consider the problem of discovering and representing the topology of a modular self-reconfigurable robot (MSR) in which modules do not have a priori information about other modules that belong to the same configuration. We propose a solution that combines two main features of modules - their geometric shape and their inter-connection with other modules, represented as a connectivity graph. We describe a distributed algorithm that can be used by each module to construct the connectivity graph by discovering other modules in four steps - sharing IDs, creating a local configuration structure (LCS) or list of local neighbors, sharing a matrix with LCSs to adjacent modules, and building an adjacency matrix by combining LCSs. Data is exchanged between modules using infra-red (IR) communication. Our proposed technique can operate within limited computational resources available on a module and is robust to module failures. We have tested and demonstrated the successful operation of our proposed technique on the ModRED (Modular Robot for Exploration and Discovery) platform and shown that modules are able to discover both linear and branched configurations using our algorithm.