# Path: lib/process.py
# def get_simple_cmd_output(cmd, stderr=STDOUT):
# def get_complex_cmd_output(cmd, stderr=STDOUT):
# def get_cmd_output_input_from_stdin(cmd, input_file):
# def get_return_code_of_simple_cmd(cmd, stderr=STDOUT):
# def get_exitcode_stdout_stderr(cmd):
# def execute_cmd(cmd):
# def execute_cmd_in_background(cmd):
# def get_process_list():
# def keep_alive(cmd):
# def is_process_running(pname):
# 
# Path: lib/process.py
# def get_return_code_of_simple_cmd(cmd, stderr=STDOUT):
#     """Execute a simple external command and return its exit status."""
#     args = shlex.split(cmd)
#     return call(args, stdout=PIPE, stderr=stderr)
# 
# Path: lib/web.py
# def get_page(url, debug=False, user_agent=True, timeout=MAX):
#     try:
#         with Timeout(timeout):
#             if user_agent:
#                 r = requests.get(url, headers=headers, timeout=timeout)
#             else:
#                 r = requests.get(url, timeout=timeout)
#             #
#             return r.text
#     except Timeout.Timeout:
#         if debug:
#             print("# timeout error", file=sys.stderr)
#         return None
#     except requests.exceptions.ConnectionError as e:
#         if debug:
#             print("#", e, file=sys.stderr)
#         return None


import json
import re
import socket
from lib import process
from lib.process import get_return_code_of_simple_cmd
from lib.web import get_page
from six.moves.urllib import error, request
            request.urlopen('http://www.google.com', timeout=3)
            return True
        except error.URLError:
            return False
        except socket.timeout:
            return False
    elif method == 3:
        cmd = "ping -c 1 www.google.com"
        return get_return_code_of_simple_cmd(cmd) == 0
    else:
        print('# warning: unknown method in is_internet_on()')


def get_my_external_ip():
    """
    Get my external IP.

    Local IP: http://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib
    """
    content = get_page("http://jsonip.com/")
    if content:
        d = json.loads(content)
        return d["ip"]
    else:
        return None


def ping(host, cnt=1):
    """Ping a URL and return the average ping time."""
    cmd = 'ping -c {cnt} {url}'.format(url=host, cnt=cnt)

# Path: lib/process.py
# def get_simple_cmd_output(cmd, stderr=STDOUT):
# def get_complex_cmd_output(cmd, stderr=STDOUT):
# def get_cmd_output_input_from_stdin(cmd, input_file):
# def get_return_code_of_simple_cmd(cmd, stderr=STDOUT):
# def get_exitcode_stdout_stderr(cmd):
# def execute_cmd(cmd):
# def execute_cmd_in_background(cmd):
# def get_process_list():
# def keep_alive(cmd):
# def is_process_running(pname):
# 
# Path: lib/process.py
# def get_return_code_of_simple_cmd(cmd, stderr=STDOUT):
#     """Execute a simple external command and return its exit status."""
#     args = shlex.split(cmd)
#     return call(args, stdout=PIPE, stderr=stderr)
# 
# Path: lib/web.py
# def get_page(url, debug=False, user_agent=True, timeout=MAX):
#     try:
#         with Timeout(timeout):
#             if user_agent:
#                 r = requests.get(url, headers=headers, timeout=timeout)
#             else:
#                 r = requests.get(url, timeout=timeout)
#             #
#             return r.text
#     except Timeout.Timeout:
#         if debug:
#             print("# timeout error", file=sys.stderr)
#         return None
#     except requests.exceptions.ConnectionError as e:
#         if debug:
#             print("#", e, file=sys.stderr)
#         return None


# Path: lib/network.py
import json
import re
import socket
from lib import process
from lib.process import get_return_code_of_simple_cmd
from lib.web import get_page
from six.moves.urllib import error, request

            request.urlopen('http://www.google.com', timeout=3)
            return True
        except error.URLError:
            return False
        except socket.timeout:
            return False
    elif method == 3:
        cmd = "ping -c 1 www.google.com"
        return get_return_code_of_simple_cmd(cmd) == 0
    else:
        print('# warning: unknown method in is_internet_on()')


def get_my_external_ip():
    """
    Get my external IP.

    Local IP: http://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib
    """
    content = get_page("http://jsonip.com/")
    if content:
        d = json.loads(content)
        return d["ip"]
    else:
        return None


def ping(host, cnt=1):
    """Ping a URL and return the average ping time."""
    cmd = 'ping -c {cnt} {url}'.format(url=host, cnt=cnt)

    output = [x for x in process.get_simple_cmd_output(cmd).split('\n') if x]