Inheritance: NetworkInterface
Esempio n. 1
0
        public static NetworkInterface [] GetAllNetworkInterfaces()
        {
#if MONOTOUCH
            return(MacOsNetworkInterface.ImplGetAllNetworkInterfaces());
#else
            if (runningOnUnix)
            {
                try {
                    if (Platform.IsMacOS)
                    {
                        return(MacOsNetworkInterface.ImplGetAllNetworkInterfaces());
                    }
                    else
                    {
                        return(LinuxNetworkInterface.ImplGetAllNetworkInterfaces());
                    }
                } catch (SystemException ex) {
                    throw ex;
                } catch {
                    return(new NetworkInterface [0]);
                }
            }
            else
            {
                if (Environment.OSVersion.Version >= windowsVer51)
                {
                    return(Win32NetworkInterface2.ImplGetAllNetworkInterfaces());
                }
                return(new NetworkInterface [0]);
            }
#endif
        }
        private unsafe static Win32_IP_ADAPTER_INFO[] GetAdaptersInfo()
        {
            byte[] array = null;
            int    num   = 0;

            Win32NetworkInterface2.GetAdaptersInfo(array, ref num);
            array = new byte[num];
            int adaptersInfo = Win32NetworkInterface2.GetAdaptersInfo(array, ref num);

            if (adaptersInfo != 0)
            {
                throw new NetworkInformationException(adaptersInfo);
            }
            List <Win32_IP_ADAPTER_INFO> list = new List <Win32_IP_ADAPTER_INFO>();

            fixed(byte *value = ref (array != null && array.Length != 0)?ref array[0] : ref *null)
            {
                IntPtr intPtr = (IntPtr)((void *)value);

                while (intPtr != IntPtr.Zero)
                {
                    Win32_IP_ADAPTER_INFO win32_IP_ADAPTER_INFO = new Win32_IP_ADAPTER_INFO();
                    Marshal.PtrToStructure(intPtr, win32_IP_ADAPTER_INFO);
                    list.Add(win32_IP_ADAPTER_INFO);
                    intPtr = win32_IP_ADAPTER_INFO.Next;
                }
            }

            return(list.ToArray());
        }
Esempio n. 3
0
 public static NetworkInterface[] ImplGetAllNetworkInterfaces()
 {
     Win32_IP_ADAPTER_ADDRESSES[] adaptersAddresses = GetAdaptersAddresses();
     NetworkInterface[]           array             = new NetworkInterface[adaptersAddresses.Length];
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = new Win32NetworkInterface2(adaptersAddresses[i]);
     }
     return(array);
 }
Esempio n. 4
0
 public override NetworkInterface [] GetAllNetworkInterfaces()
 {
     //			Win32_IP_ADAPTER_INFO [] ai = GetAdaptersInfo ();
     Win32_IP_ADAPTER_ADDRESSES [] aa  = GetAdaptersAddresses();
     NetworkInterface []           ret = new NetworkInterface [aa.Length];
     for (int i = 0; i < ret.Length; i++)
     {
         ret [i] = new Win32NetworkInterface2(aa [i]);
     }
     return(ret);
 }
 public static Win32_IP_ADAPTER_INFO GetAdapterInfoByIndex(int index)
 {
     foreach (Win32_IP_ADAPTER_INFO win32_IP_ADAPTER_INFO in Win32NetworkInterface2.GetAdaptersInfo())
     {
         if ((ulong)win32_IP_ADAPTER_INFO.Index == (ulong)((long)index))
         {
             return(win32_IP_ADAPTER_INFO);
         }
     }
     return(null);
 }
Esempio n. 6
0
        public static NetworkInterface [] GetAllNetworkInterfaces()
        {
            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Unix:
                return(new NetworkInterface [0]);

            default:
                if (Environment.OSVersion.Version >= new Version(5, 1))
                {
                    return(Win32NetworkInterface2.ImplGetAllNetworkInterfaces());
                }
                return(new NetworkInterface [0]);
            }
        }
 private Win32NetworkInterface2(Win32_IP_ADAPTER_ADDRESSES addr)
 {
     this.addr       = addr;
     this.mib4       = default(Win32_MIB_IFROW);
     this.mib4.Index = addr.Alignment.IfIndex;
     if (Win32NetworkInterface2.GetIfEntry(ref this.mib4) != 0)
     {
         this.mib4.Index = -1;
     }
     this.mib6       = default(Win32_MIB_IFROW);
     this.mib6.Index = addr.Ipv6IfIndex;
     if (Win32NetworkInterface2.GetIfEntry(ref this.mib6) != 0)
     {
         this.mib6.Index = -1;
     }
     this.ip4stats    = new Win32IPv4InterfaceStatistics(this.mib4);
     this.ip_if_props = new Win32IPInterfaceProperties2(addr, this.mib4, this.mib6);
 }
Esempio n. 8
0
        public static NetworkInterface[] GetAllNetworkInterfaces()
        {
            if (runningOnUnix)
            {
                bool   flag   = false;
                IntPtr intPtr = Marshal.AllocHGlobal(8192);
                if (uname(intPtr) == 0)
                {
                    string a = Marshal.PtrToStringAnsi(intPtr);
                    if (a == "Darwin")
                    {
                        flag = true;
                    }
                }
                Marshal.FreeHGlobal(intPtr);
                try
                {
                    if (flag)
                    {
                        return(MacOsNetworkInterface.ImplGetAllNetworkInterfaces());
                    }
                    return(LinuxNetworkInterface.ImplGetAllNetworkInterfaces());

                    IL_005f :;
                }
                catch (SystemException ex)
                {
                    throw ex;
                    IL_0067 :;
                }
                catch
                {
                    return(new NetworkInterface[0]);

                    IL_007a :;
                }
            }
            if (Environment.OSVersion.Version >= windowsVer51)
            {
                return(Win32NetworkInterface2.ImplGetAllNetworkInterfaces());
            }
            return(new NetworkInterface[0]);
        }
Esempio n. 9
0
        public static NetworkInterface [] GetAllNetworkInterfaces()
        {
            if (runningOnUnix)
            {
                bool   darwin = false;
                IntPtr buf    = Marshal.AllocHGlobal(8192);
                if (uname(buf) == 0)
                {
                    string os = Marshal.PtrToStringAnsi(buf);
                    if (os == "Darwin")
                    {
                        darwin = true;
                    }
                }
                Marshal.FreeHGlobal(buf);

                try {
                    if (darwin)
                    {
                        return(MacOsNetworkInterface.ImplGetAllNetworkInterfaces());
                    }
                    else
                    {
                        return(LinuxNetworkInterface.ImplGetAllNetworkInterfaces());
                    }
                } catch (SystemException ex) {
                    throw ex;
                } catch {
                    return(new NetworkInterface [0]);
                }
            }
            else
            {
                if (Environment.OSVersion.Version >= windowsVer51)
                {
                    return(Win32NetworkInterface2.ImplGetAllNetworkInterfaces());
                }
                return(new NetworkInterface [0]);
            }
        }
Esempio n. 10
0
		public static NetworkInterface [] ImplGetAllNetworkInterfaces ()
		{
//			Win32_IP_ADAPTER_INFO [] ai = GetAdaptersInfo ();
			Win32_IP_ADAPTER_ADDRESSES [] aa = GetAdaptersAddresses ();
			NetworkInterface [] ret = new NetworkInterface [aa.Length];
			for (int i = 0; i < ret.Length; i++)
				ret [i] = new Win32NetworkInterface2 (aa [i]);
			return ret;
		}
Esempio n. 11
0
        public override IPv6InterfaceProperties GetIPv6Properties()
        {
            Win32_IP_ADAPTER_INFO v6info = Win32NetworkInterface2.GetAdapterInfoByIndex(mib6.Index);

            return(v6info != null ? new Win32IPv6InterfaceProperties(mib6) : null);
        }
Esempio n. 12
0
        public override IPv4InterfaceProperties GetIPv4Properties()
        {
            Win32_IP_ADAPTER_INFO v4info = Win32NetworkInterface2.GetAdapterInfoByIndex(mib4.Index);

            return(v4info != null ? new Win32IPv4InterfaceProperties(v4info, mib4) : null);
        }
        public override IPv6InterfaceProperties GetIPv6Properties()
        {
            Win32_IP_ADAPTER_INFO adapterInfoByIndex = Win32NetworkInterface2.GetAdapterInfoByIndex(this.mib6.Index);

            return((adapterInfoByIndex == null) ? null : new Win32IPv6InterfaceProperties(this.mib6));
        }