Mark Pilgrim demonstrated such a piece of code at the 2014 Kansasfest - but all I can find about it is a few screenshots and an Apple ][ disk image. (There's also a link to run the image in an in-browser emulation using JSMess - see here.)
I wonder if anyone is interested in digging in, reverse-engineering the code, and discovering how Mark tackled the challenge.

Quote:
Self-booting disk that can detect if it is running in (known) Apple II emulators.
Presented at the 2014 Kansasfest Apple II convention, this self-booting disk image will detect a number of major emulators. Utilizing differences in the amount of self-sync bytes after the data epilogue, multiple emulators and "real" hardware can be surmised.
Presented at the 2014 Kansasfest Apple II convention, this self-booting disk image will detect a number of major emulators. Utilizing differences in the amount of self-sync bytes after the data epilogue, multiple emulators and "real" hardware can be surmised.