#!/bin/bash

# Check if root
# if [ "$EUID" -ne 0 ]
#   then echo "Please run as root"
#   exit
# fi

# Check network has access to the Internet
nc -z -w 5 8.8.8.8 53  >/dev/null 2>&1
online=$?
if [ $online -eq 0 ]; then
      # Check that DNS resolves domain names propperly
      response=$(getent hosts www.salicru.com | awk '{ print $1 }')
      if [[ ! $response ]]
      then
            # There is Internet access, but DNS does not resolve domain names
            echo "1"
      else
            # There is Internet access with DNS resoultion
            echo "2"
      fi
else
      # There is no Internet access
        echo "0"
fi