import urllib.request, urllib.error, urllib.parse, socket


def internet_access(timeout=1):
    """Return True if internet is on, else False."""
    try:
        # Check google.com with numerical IP-address (which avoids
        # DNS loopup) and set timeout to 1 sec so this does not
        # take much time (google.com should respond quickly)
       #response = urllib2.urlopen('http://8.8.8.8', timeout=timeout)
       response = urllib.request.urlopen('http://vg.no', timeout=timeout)
       return True
    except (urllib.error.URLError, socket.timeout) as err:
        pass
    return False