It depends what you want to do with those peers: if you're looking at ip+port addresses, you can simply get a list of known peers on the network by just leaving a stellar-core running for a while.
This will build a list of peers in its "peers" table (an instance only connects to a small subset of that list). For this particular scenario you don't need to re-implement the p2p protocol.
You can dump the content of that peers table by connecting to the SQL instance that you configured stellar-core with (sqlite is probably good enough for this btw). I don't think there is a command to return the content of that table (the peers
command only returns peers connected to).
If you're looking at building a list of validators (including their public key) - it's trickier, I imagine that you'd need to record the key of the validator somewhere after connecting to it (that key is not persisted in the peers table).