How do altcoins tell each other apart?
Because all these altcoins run on different TCP ports and furthermore (fair) nodes won't relay invalid messages (wrong blockchain, i.e. based on different genesis block, different magic value,  etc.) or IP addresses of nodes running other altcoins.