Write a program which, according to whether the script has access to the internet, produces an output which is "Truthy/Falsey". You may try and connect to any existing site, at your own discretion (don't use a shady site which only has 10% uptime - try to keep to above 80% annual uptime). If the site is down, your program does not have to work.
It must be a standalone program or a function. You may use libraries outside of the standard library to achieve this. Standard loopholes are forbidden. This is code golf, so the code with the shortest byte-count wins.
Example pseudocode:
function a:
try:
connect to internet
return 1
catch error:
return 0
This is my first post on code golf, so if this violates any rules in any way or is a dupe, please alert me.
EDIT: Due to numerous suggestions, I have removed the UTF-8 byte count restriction
true
andfalse
, I recommend allowing any of our defaults for truthy and falsiness. Also, by internet, do you mean the network outside your local network? Do programs still have to work if say google is down or any other large site? \$\endgroup\$g.gl
/http://g.gl/
, butto.
/http://to./
seems to be one byte shorter (not all languages see it as a valid url through). \$\endgroup\$PRINT "0"
\$\endgroup\$