PS: I haven't tried his method but, it looks reasonable and, seems to be along the lines of what you're asking for.
Well... I have tried it some ions ago that's why I have this service. (Actually
two, one is more advanced and detects redirects, see much older postings for context).
Boils down to: the only way to test for an internet connection is by
making a connection to a reliable server.
In my case I give you your ip for free....
and as a string...not polluted by any html....
Also... well... check my websites....Boring...