Skip to content

Instantly share code, notes, and snippets.

@professorjamesmoriarty
Created February 24, 2016 21:19
Show Gist options
  • Save professorjamesmoriarty/084c86f2f7e8ac24561e to your computer and use it in GitHub Desktop.
Save professorjamesmoriarty/084c86f2f7e8ac24561e to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2016 Johnathan "Shaggytwodope" Jenkins <[email protected]>
#
# Distributed under terms of the MIT license.
"""
Tool to check if online, returns exit status 0 if succesful or 1 if not.
"""
import urllib.request
import sys
def connected(host='http://google.com'):
try:
urllib.request.urlopen(host)
return True
except:
return False
if connected():
print('connected')
sys.exit(0)
else:
print('no connection')
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment