Here's my stab at a possible solution. Please feel free to rip it apart.
1) from blockchain: during daemon startup, walk last 4000 blocks, collect paid masternode addresses.
2) from network: collate all masternode addresses from peers into array 'mnlist'
3) prune masternode addresses having...