Templating. Check if entity is comment or node?
Assuming this is for Drupal 7, there isn't an official way to do this, unfortunately. See core issue: https://www.drupal.org/node/1042822

One possible workaround is to check if the entity has some known fields that you are aware of. This obviously wouldn't be a generalized solution - but might work for you.