use the core function wp_get_sites() for get all sites inside the network, new in wp 3.7 core