Search Unity

Simple internet checker C#

Discussion in 'Scripting' started by eanjo7, Jul 28, 2014.

  1. eanjo7

    eanjo7

    Joined:
    Jun 1, 2014
    Posts:
    42
    I search all trough the internet.

    does anyone know how to do a simple internet checker??
    (if has internet or not)
     
  2. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
  3. eanjo7

    eanjo7

    Joined:
    Jun 1, 2014
    Posts:
    42
    what you send is not c# and not simple
     
  4. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NetAvailable : MonoBehaviour
    5. {
    6.  
    7.     void Start()
    8.     {
    9.         if(Method1())
    10.         {
    11.             Debug.Log("HAS INTERNET ACCESS");
    12.         }
    13.         else
    14.         {
    15.             Debug.Log("NO INTERNET ACCESS");
    16.         }
    17.     }
    18.  
    19.     bool Method1()
    20.     {
    21.         if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
    22.             return true;
    23.         return false;
    24.     }
    25.  
    26.     //Pauses thread
    27.     bool Method2()
    28.     {
    29.         try
    30.         {
    31.             System.Net.Dns.GetHostEntry("www.google.com");
    32.             return true;
    33.         }
    34.         catch
    35.         {
    36.             return false;
    37.         }
    38.     }
    39.  
    40. }
     
    lrlelaldl likes this.
  5. eanjo7

    eanjo7

    Joined:
    Jun 1, 2014
    Posts:
    42
    hey thanks for the help!