Ejemplo n.º 1
0
        List <IPAddress> CollectAddresses(JNetworkInterface inf)
        {
            var ret = new List <IPAddress> ();

            Java.Util.IEnumeration addresses = inf.InetAddresses;
            while (addresses.HasMoreElements)
            {
                var addr = addresses.NextElement() as InetAddress;
                if (addr == null)
                {
                    continue;
                }
                var ipv6 = addr as Inet6Address;
                if (ipv6 != null && (ipv6.IsLinkLocalAddress || ipv6.IsMCLinkLocal))
                {
                    ret.Add(new IPAddress(addr.GetAddress(), ipv6.ScopeId));
                }
                else
                {
                    ret.Add(new IPAddress(addr.GetAddress()));
                }
            }

            return(ret);
        }
Ejemplo n.º 2
0
 // thank you deapsquatter - https://gist.github.com/deapsquatter/5644550
 /// <summary>
 /// Allows a Java.Util.IEnumeration to be enumerated as an IEnumerable.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="enumeration"></param>
 /// <returns></returns>
 public static IEnumerable <T> GetEnumerable <T>(this Java.Util.IEnumeration enumeration) where T : class
 {
     while (enumeration.HasMoreElements)
     {
         yield return(enumeration.NextElement() as T);
     }
 }
Ejemplo n.º 3
0
        public bool CBCMGWiFiConnected()
        {
            bool   wc     = false;
            bool   gc     = false;
            String WiFiIP = null;

            if (WiFiStatus() == NetworkState.ConnectedWifi)
            {
                wc = true;
                PlayWiFiConnected();
                Java.Util.IEnumeration networkInterfaces = Java.Net.NetworkInterface.NetworkInterfaces;
                while (networkInterfaces.HasMoreElements)
                {
                    Java.Net.NetworkInterface netInterface = (Java.Net.NetworkInterface)networkInterfaces.NextElement();
                    Java.Util.IEnumeration    a            = netInterface.InetAddresses;
                    while (a.HasMoreElements)
                    {
                        Java.Net.InetAddress b = (Java.Net.InetAddress)a.NextElement();
                        String IP = b.GetAddress()[0] + "." + b.GetAddress()[1] + "." + b.GetAddress()[2] + "." + b.GetAddress()[3];
                        if (IP.StartsWith(IPRange, StringComparison.Ordinal))
                        {
                            WiFiIP = IP;
                            gc     = true;
                            PlayCBCMGWiFiConnected();
                        }
                    }
                }
            }
            LOGMSG("IP " + WiFiIP + " WiFi connected: " + wc + " CBCMG connected: " + gc + " " + sd.GetEnabled() + ":" + WiFiConnectDateTime + " " + WiFiDisconnectWarning + ":" + WiFiDisconnectDateTime + " " + sd.GetMovingDateTime());
            return(gc);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Cast a IEnumeration to an IEnumerable<typeparamref name="T" />. Will throw an InvalidCastException if any element in the enumeration cannot be cast.
 /// </summary>
 /// <typeparam name="T">The type of the elements.</typeparam>
 /// <param name="enumeration">The enumeration.</param>
 /// <returns>An enumerable with elements of the specified type.</returns>
 /// <exception cref="System.InvalidCastException">If one of the elements cannot be cast.</exception>
 public static IEnumerable <T> Cast <T>(this Java.Util.IEnumeration enumeration)
     where T : Java.Lang.Object
 {
     while (enumeration.HasMoreElements)
     {
         yield return((T)enumeration.NextElement());
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Return an IEnumerable<typeparamref name="T"/> with all the elements in the IEnumeration which match the required type, other elements are ignored.
 /// </summary>
 /// <typeparam name="T">The type of the elements.</typeparam>
 /// <param name="enumeration">The enumeration.</param>
 /// <returns>An enumerable with elements that match the specified type.</returns>
 public static IEnumerable <T> OfType <T>(this Java.Util.IEnumeration enumeration)
     where T : Java.Lang.Object
 {
     while (enumeration.HasMoreElements)
     {
         Java.Lang.Object element = enumeration.NextElement();
         if (element is T)
         {
             yield return((T)element);
         }
     }
 }
Ejemplo n.º 6
0
        List <IPAddress> CollectAddresses(JNetworkInterface inf)
        {
            var ret = new List <IPAddress> ();

            Java.Util.IEnumeration addresses = inf.InetAddresses;
            while (addresses.HasMoreElements)
            {
                var addr = addresses.NextElement() as InetAddress;
                if (addr == null)
                {
                    continue;
                }
                ret.Add(new IPAddress(addr.GetAddress()));
            }

            return(ret);
        }
Ejemplo n.º 7
0
        List <InterfaceInfo> GetInfos(Java.Util.IEnumeration interfaces)
        {
            var ret = new List <InterfaceInfo> ();

            while (interfaces.HasMoreElements)
            {
                var inf = interfaces.NextElement() as JNetworkInterface;
                if (inf == null)
                {
                    continue;
                }

                ret.Add(new InterfaceInfo {
                    Name            = inf.Name,
                    IsLoopback      = inf.IsLoopback,
                    IsUp            = inf.IsUp,
                    HardwareAddress = inf.GetHardwareAddress(),
                    Addresses       = CollectAddresses(inf)
                });
            }

            return(ret);
        }