예제 #1
0
        internal SystemIPv4InterfaceProperties(FixedInfo fixedInfo, IpAdapterInfo ipAdapterInfo)
        {
            this.index            = ipAdapterInfo.index;
            this.routingEnabled   = fixedInfo.EnableRouting;
            this.dhcpEnabled      = ipAdapterInfo.dhcpEnabled;
            this.haveWins         = ipAdapterInfo.haveWins;
            this.gatewayAddresses = ipAdapterInfo.gatewayList.ToIPGatewayAddressCollection();
            this.dhcpAddresses    = ipAdapterInfo.dhcpServer.ToIPAddressCollection();
            IPAddressCollection addresss  = ipAdapterInfo.primaryWinsServer.ToIPAddressCollection();
            IPAddressCollection addresss2 = ipAdapterInfo.secondaryWinsServer.ToIPAddressCollection();

            this.winsServerAddresses = new IPAddressCollection();
            foreach (IPAddress address in addresss)
            {
                this.winsServerAddresses.InternalAdd(address);
            }
            foreach (IPAddress address2 in addresss2)
            {
                this.winsServerAddresses.InternalAdd(address2);
            }
            SystemIPv4InterfaceStatistics statistics = new SystemIPv4InterfaceStatistics((long)this.index);

            this.mtu = (uint)statistics.Mtu;
            if (ComNetOS.IsWin2K)
            {
                this.GetPerAdapterInfo(ipAdapterInfo.index);
            }
            else
            {
                this.dnsAddresses = fixedInfo.DnsAddresses;
            }
        }
 internal bool Update(FixedInfo fixedInfo, IpAdapterInfo ipAdapterInfo)
 {
     try
     {
         foreach (IPExtendedAddress address in ipAdapterInfo.ipAddressList.ToIPExtendedAddressArrayList())
         {
             foreach (SystemUnicastIPAddressInformation information in this.unicastAddresses)
             {
                 if (address.address.Equals(information.Address))
                 {
                     information.ipv4Mask = address.mask;
                 }
             }
         }
         this.ipv4Properties = new SystemIPv4InterfaceProperties(fixedInfo, ipAdapterInfo);
         if ((this.dnsAddresses == null) || (this.dnsAddresses.Count == 0))
         {
             this.dnsAddresses = this.ipv4Properties.DnsAddresses;
         }
     }
     catch (NetworkInformationException exception)
     {
         if (((exception.ErrorCode != 0x57L) && (exception.ErrorCode != 13L)) && (((exception.ErrorCode != 0xe8L) && (exception.ErrorCode != 1L)) && (exception.ErrorCode != 2L)))
         {
             throw;
         }
         return(false);
     }
     return(true);
 }
 internal SystemIPInterfaceProperties(FixedInfo fixedInfo, IpAdapterAddresses ipAdapterAddresses)
 {
     this.dnsEnabled = fixedInfo.EnableDns;
     this.index      = ipAdapterAddresses.index;
     this.name       = ipAdapterAddresses.AdapterName;
     this.ipv6Index  = ipAdapterAddresses.ipv6Index;
     if (this.index > 0)
     {
         this.versionSupported |= IPVersion.IPv4;
     }
     if (this.ipv6Index > 0)
     {
         this.versionSupported |= IPVersion.IPv6;
     }
     this.mtu                = ipAdapterAddresses.mtu;
     this.adapterFlags       = ipAdapterAddresses.flags;
     this.dnsSuffix          = ipAdapterAddresses.dnsSuffix;
     this.dynamicDnsEnabled  = (ipAdapterAddresses.flags & AdapterFlags.DnsEnabled) > 0;
     this.multicastAddresses = SystemMulticastIPAddressInformation.ToAddressInformationCollection(ipAdapterAddresses.FirstMulticastAddress);
     this.dnsAddresses       = SystemIPAddressInformation.ToAddressCollection(ipAdapterAddresses.FirstDnsServerAddress, this.versionSupported);
     this.anycastAddresses   = SystemIPAddressInformation.ToAddressInformationCollection(ipAdapterAddresses.FirstAnycastAddress, this.versionSupported);
     this.unicastAddresses   = SystemUnicastIPAddressInformation.ToAddressInformationCollection(ipAdapterAddresses.FirstUnicastAddress);
     if (this.ipv6Index > 0)
     {
         this.ipv6Properties = new SystemIPv6InterfaceProperties(this.ipv6Index, this.mtu);
     }
 }
예제 #4
0
        void GetDNSServersFromOS()
        {
            IntPtr dsa;
            int    len = _monodroid_get_dns_servers(out dsa);

            if (len <= 0)
            {
                return;
            }

            var servers = new IntPtr [len];

            Marshal.Copy(dsa, servers, 0, len);

            dns_servers = new IPAddressCollection();
            foreach (IntPtr s in servers)
            {
                string server_ip = Marshal.PtrToStringAnsi(s);
                Marshal.FreeHGlobal(s);

                IPAddress addr;
                if (!IPAddress.TryParse(server_ip, out addr))
                {
                    continue;
                }
                dns_servers.InternalAdd(addr);
            }
            Marshal.FreeHGlobal(dsa);
        }
예제 #5
0
 public LinuxGatewayIPAddressInformationCollection(IPAddressCollection col)
 {
     foreach (IPAddress address in col)
     {
         this.Add(new GatewayIPAddressInformationImpl(address));
     }
     this.is_readonly = true;
 }
 public UnixGatewayIPAddressInformationCollection(IPAddressCollection col)
 {
     foreach (IPAddress a in col)
     {
         Add(new GatewayIPAddressInformationImpl(a));
     }
     this.is_readonly = true;
 }
예제 #7
0
        void ParseResolvConf()
        {
            try
            {
                DateTime wt = File.GetLastWriteTime("/etc/resolv.conf");
                if (wt <= last_parse)
                {
                    return;
                }

                last_parse  = wt;
                dns_suffix  = "";
                dns_servers = new IPAddressCollection();
                using (StreamReader reader = new StreamReader("/etc/resolv.conf"))
                {
                    string str;
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line.Length == 0 || line [0] == '#')
                        {
                            continue;
                        }
                        Match match = ns.Match(line);
                        if (match.Success)
                        {
                            try
                            {
                                str = match.Groups ["address"].Value;
                                str = str.Trim();
                                dns_servers.Add(IPAddress.Parse(str));
                            }
                            catch
                            {
                            }
                        }
                        else
                        {
                            match = search.Match(line);
                            if (match.Success)
                            {
                                str = match.Groups ["domain"].Value;
                                string [] parts = str.Split(',');
                                dns_suffix = parts [0].Trim();
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                dns_servers.SetReadOnly();
            }
        }
예제 #8
0
 public UnixIPInterfaceProperties(UnixNetworkInterface uni, bool globalConfig = false)
 {
     _uni = uni;
     if (!globalConfig)
     {
         _dnsSuffix    = GetDnsSuffix();
         _dnsAddresses = GetDnsAddresses();
     }
 }
 private void ParseResolvConf()
 {
     try
     {
         DateTime lastWriteTime = File.GetLastWriteTime("/etc/resolv.conf");
         if (!(lastWriteTime <= this.last_parse))
         {
             this.last_parse  = lastWriteTime;
             this.dns_suffix  = string.Empty;
             this.dns_servers = new IPAddressCollection();
             using (StreamReader streamReader = new StreamReader("/etc/resolv.conf"))
             {
                 string text;
                 while ((text = streamReader.ReadLine()) != null)
                 {
                     text = text.Trim();
                     if (text.Length != 0 && text[0] != '#')
                     {
                         System.Text.RegularExpressions.Match match = UnixIPInterfaceProperties.ns.Match(text);
                         if (match.Success)
                         {
                             try
                             {
                                 string text2 = match.Groups["address"].Value;
                                 text2 = text2.Trim();
                                 this.dns_servers.Add(IPAddress.Parse(text2));
                             }
                             catch
                             {
                             }
                         }
                         else
                         {
                             match = UnixIPInterfaceProperties.search.Match(text);
                             if (match.Success)
                             {
                                 string   text2 = match.Groups["domain"].Value;
                                 string[] array = text2.Split(new char[]
                                 {
                                     ','
                                 });
                                 this.dns_suffix = array[0].Trim();
                             }
                         }
                     }
                 }
             }
         }
     }
     catch
     {
     }
     finally
     {
         this.dns_servers.SetReadOnly();
     }
 }
 public LinuxIPInterfaceProperties(LinuxNetworkInterface lni)
     : base(lni)
 {
     _linuxNetworkInterface = lni;
     _gatewayAddresses      = GetGatewayAddresses();
     _dhcpServerAddresses   = GetDhcpServerAddresses();
     _winsServerAddresses   = GetWinsServerAddresses();
     _ipv4Properties        = new LinuxIPv4InterfaceProperties(lni);
     _ipv6Properties        = new LinuxIPv6InterfaceProperties(lni);
 }
 private void ParseResolvConf()
 {
     try
     {
         DateTime lastWriteTime = File.GetLastWriteTime("/etc/resolv.conf");
         if (!(lastWriteTime <= last_parse))
         {
             last_parse  = lastWriteTime;
             dns_suffix  = string.Empty;
             dns_servers = new IPAddressCollection();
             using (StreamReader streamReader = new StreamReader("/etc/resolv.conf"))
             {
                 string text;
                 while ((text = streamReader.ReadLine()) != null)
                 {
                     text = text.Trim();
                     if (text.Length != 0 && text[0] != '#')
                     {
                         Match match = ns.Match(text);
                         if (match.Success)
                         {
                             try
                             {
                                 string value = match.Groups["address"].Value;
                                 value = value.Trim();
                                 dns_servers.Add(IPAddress.Parse(value));
                             }
                             catch
                             {
                             }
                         }
                         else
                         {
                             match = search.Match(text);
                             if (match.Success)
                             {
                                 string   value = match.Groups["domain"].Value;
                                 string[] array = value.Split(',');
                                 dns_suffix = array[0].Trim();
                             }
                         }
                     }
                 }
             }
         }
     }
     catch
     {
     }
     finally
     {
         dns_servers.SetReadOnly();
     }
 }
 public LinuxIPInterfaceProperties(LinuxNetworkInterface lni, LinuxNetworkInterface.LinuxNetworkInterfaceSystemProperties systemProperties)
     : base(lni, globalConfig: true)
 {
     _linuxNetworkInterface = lni;
     _gatewayAddresses      = GetGatewayAddresses(systemProperties);
     _dhcpServerAddresses   = GetDhcpServerAddresses();
     _winsServerAddresses   = GetWinsServerAddresses();
     _dnsSuffix             = systemProperties.DnsSuffix;
     _dnsAddresses          = systemProperties.DnsAddresses;
     _ipv4Properties        = new LinuxIPv4InterfaceProperties(lni);
     _ipv6Properties        = new LinuxIPv6InterfaceProperties(lni);
 }
예제 #13
0
        internal static IPAddressCollection MarshalIpAddressCollection(IntPtr ptr)
        {
            IPAddressCollection addressList = new IPAddressCollection();

            while (ptr != IntPtr.Zero)
            {
                IpAdapterAddress addressStructure =
                    (IpAdapterAddress)Marshal.PtrToStructure(ptr, typeof(IpAdapterAddress));
                IPAddress address = addressStructure.address.MarshalIPAddress();
                addressList.InternalAdd(address);
                ptr = addressStructure.next;
            }

            return(addressList);
        }
예제 #14
0
        void ParseRouteInfo(string iface)
        {
            try
            {
                gateways = new IPAddressCollection();
                using (StreamReader reader = new StreamReader("/proc/net/route"))
                {
                    string line;
                    reader.ReadLine(); // Ignore first line
                    while ((line = reader.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line.Length == 0)
                        {
                            continue;
                        }

                        string [] parts = line.Split('\t');
                        if (parts.Length < 3)
                        {
                            continue;
                        }
                        string  gw_address = parts [2].Trim();
                        byte [] ipbytes    = new byte [4];
                        if (gw_address.Length == 8 && iface.Equals(parts [0], StringComparison.OrdinalIgnoreCase))
                        {
                            for (int i = 0; i < 4; i++)
                            {
                                if (!Byte.TryParse(gw_address.Substring(i * 2, 2), NumberStyles.HexNumber, null, out ipbytes [3 - i]))
                                {
                                    continue;
                                }
                            }
                            IPAddress ip = new IPAddress(ipbytes);
                            if (!ip.Equals(IPAddress.Any))
                            {
                                gateways.Add(ip);
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }
 private void ParseRouteInfo(string iface)
 {
     try
     {
         this.gateways = new IPAddressCollection();
         using (StreamReader streamReader = new StreamReader("/proc/net/route"))
         {
             streamReader.ReadLine();
             string text;
             while ((text = streamReader.ReadLine()) != null)
             {
                 text = text.Trim();
                 if (text.Length != 0)
                 {
                     string[] array = text.Split(new char[]
                     {
                         '\t'
                     });
                     if (array.Length >= 3)
                     {
                         string text2  = array[2].Trim();
                         byte[] array2 = new byte[4];
                         if (text2.Length == 8 && iface.Equals(array[0], StringComparison.OrdinalIgnoreCase))
                         {
                             for (int i = 0; i < 4; i++)
                             {
                                 if (!byte.TryParse(text2.Substring(i * 2, 2), NumberStyles.HexNumber, null, out array2[3 - i]))
                                 {
                                 }
                             }
                             IPAddress ipaddress = new IPAddress(array2);
                             if (!ipaddress.Equals(IPAddress.Any))
                             {
                                 this.gateways.Add(ipaddress);
                             }
                         }
                     }
                 }
             }
         }
     }
     catch
     {
     }
 }
예제 #16
0
 private void GetPerAdapterInfo(uint index)
 {
     if (index != 0)
     {
         uint          pOutBufLen      = 0;
         SafeLocalFree pPerAdapterInfo = null;
         uint          num2            = UnsafeNetInfoNativeMethods.GetPerAdapterInfo(index, SafeLocalFree.Zero, ref pOutBufLen);
         while (num2 == 0x6f)
         {
             try
             {
                 pPerAdapterInfo = SafeLocalFree.LocalAlloc((int)pOutBufLen);
                 num2            = UnsafeNetInfoNativeMethods.GetPerAdapterInfo(index, pPerAdapterInfo, ref pOutBufLen);
                 if (num2 == 0)
                 {
                     IpPerAdapterInfo info = (IpPerAdapterInfo)Marshal.PtrToStructure(pPerAdapterInfo.DangerousGetHandle(), typeof(IpPerAdapterInfo));
                     this.autoConfigEnabled = info.autoconfigEnabled;
                     this.autoConfigActive  = info.autoconfigActive;
                     this.dnsAddresses      = info.dnsServerList.ToIPAddressCollection();
                 }
                 continue;
             }
             finally
             {
                 if (this.dnsAddresses == null)
                 {
                     this.dnsAddresses = new IPAddressCollection();
                 }
                 if (pPerAdapterInfo != null)
                 {
                     pPerAdapterInfo.Close();
                 }
             }
         }
         if (this.dnsAddresses == null)
         {
             this.dnsAddresses = new IPAddressCollection();
         }
         if (num2 != 0)
         {
             throw new NetworkInformationException((int)num2);
         }
     }
 }
예제 #17
0
 public static void DisplayAddresses()
 {
     NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
     foreach (NetworkInterface adapter in adapters)
     {
         IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
         System.Net.NetworkInformation.IPAddressCollection Servers = adapterProperties.DnsAddresses;
         if (Servers.Count > 0)
         {
             Console.WriteLine(adapter.Description);
             foreach (IPAddress dns in Servers)
             {
                 Console.WriteLine("Servers ............................. : {0}",
                                   dns.ToString());
             }
             Console.WriteLine();
         }
     }
 }
예제 #18
0
        internal IPAddressCollection ToIPAddressCollection()
        {
            IpAddrString        str      = this;
            IPAddressCollection addresss = new IPAddressCollection();

            if (str.IpAddress.Length != 0)
            {
                addresss.InternalAdd(IPAddress.Parse(str.IpAddress));
            }
            while (str.Next != IntPtr.Zero)
            {
                str = (IpAddrString)Marshal.PtrToStructure(str.Next, typeof(IpAddrString));
                if (str.IpAddress.Length != 0)
                {
                    addresss.InternalAdd(IPAddress.Parse(str.IpAddress));
                }
            }
            return(addresss);
        }
예제 #19
0
        internal static IPAddressCollection ToAddressCollection(IntPtr ptr, IPVersion versionSupported)
        {
            IPAddressCollection addresss = new IPAddressCollection();

            if (ptr != IntPtr.Zero)
            {
                IPEndPoint       point;
                IpAdapterAddress address       = (IpAdapterAddress)Marshal.PtrToStructure(ptr, typeof(IpAdapterAddress));
                AddressFamily    family        = (address.address.addressLength > 0x10) ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
                SocketAddress    socketAddress = new SocketAddress(family, address.address.addressLength);
                Marshal.Copy(address.address.address, socketAddress.m_Buffer, 0, address.address.addressLength);
                if (family == AddressFamily.InterNetwork)
                {
                    point = (IPEndPoint)IPEndPoint.Any.Create(socketAddress);
                }
                else
                {
                    point = (IPEndPoint)IPEndPoint.IPv6Any.Create(socketAddress);
                }
                addresss.InternalAdd(point.Address);
                while (address.next != IntPtr.Zero)
                {
                    address = (IpAdapterAddress)Marshal.PtrToStructure(address.next, typeof(IpAdapterAddress));
                    family  = (address.address.addressLength > 0x10) ? AddressFamily.InterNetworkV6 : AddressFamily.InterNetwork;
                    if (((family == AddressFamily.InterNetwork) && ((versionSupported & IPVersion.IPv4) > IPVersion.None)) || ((family == AddressFamily.InterNetworkV6) && ((versionSupported & IPVersion.IPv6) > IPVersion.None)))
                    {
                        socketAddress = new SocketAddress(family, address.address.addressLength);
                        Marshal.Copy(address.address.address, socketAddress.m_Buffer, 0, address.address.addressLength);
                        if (family == AddressFamily.InterNetwork)
                        {
                            point = (IPEndPoint)IPEndPoint.Any.Create(socketAddress);
                        }
                        else
                        {
                            point = (IPEndPoint)IPEndPoint.IPv6Any.Create(socketAddress);
                        }
                        addresss.InternalAdd(point.Address);
                    }
                }
            }
            return(addresss);
        }
예제 #20
0
        // This constructor is for Vista and newer
        internal SystemIPInterfaceProperties(FixedInfo fixedInfo, IpAdapterAddresses ipAdapterAddresses)
        {
            adapterFlags      = ipAdapterAddresses.flags;
            dnsSuffix         = ipAdapterAddresses.dnsSuffix;
            dnsEnabled        = fixedInfo.EnableDns;
            dynamicDnsEnabled = ((ipAdapterAddresses.flags & AdapterFlags.DnsEnabled) > 0);

            multicastAddresses = SystemMulticastIPAddressInformation.ToMulticastIpAddressInformationCollection(
                IpAdapterAddress.MarshalIpAddressInformationCollection(ipAdapterAddresses.firstMulticastAddress));
            dnsAddresses     = IpAdapterAddress.MarshalIpAddressCollection(ipAdapterAddresses.firstDnsServerAddress);
            anycastAddresses = IpAdapterAddress.MarshalIpAddressInformationCollection(
                ipAdapterAddresses.firstAnycastAddress);
            unicastAddresses = SystemUnicastIPAddressInformation.MarshalUnicastIpAddressInformationCollection(
                ipAdapterAddresses.firstUnicastAddress);
            winsServersAddresses = IpAdapterAddress.MarshalIpAddressCollection(
                ipAdapterAddresses.firstWinsServerAddress);
            gatewayAddresses = SystemGatewayIPAddressInformation.ToGatewayIpAddressInformationCollection(
                IpAdapterAddress.MarshalIpAddressCollection(ipAdapterAddresses.firstGatewayAddress));

            dhcpServers = new IPAddressCollection();
            if (ipAdapterAddresses.dhcpv4Server.address != IntPtr.Zero)
            {
                dhcpServers.InternalAdd(ipAdapterAddresses.dhcpv4Server.MarshalIPAddress());
            }
            if (ipAdapterAddresses.dhcpv6Server.address != IntPtr.Zero)
            {
                dhcpServers.InternalAdd(ipAdapterAddresses.dhcpv6Server.MarshalIPAddress());
            }

            if ((adapterFlags & AdapterFlags.IPv4Enabled) != 0)
            {
                ipv4Properties = new SystemIPv4InterfaceProperties(fixedInfo, ipAdapterAddresses);
            }

            if ((adapterFlags & AdapterFlags.IPv6Enabled) != 0)
            {
                ipv6Properties = new SystemIPv6InterfaceProperties(ipAdapterAddresses.ipv6Index,
                                                                   ipAdapterAddresses.mtu, ipAdapterAddresses.zoneIndices);
            }
        }
예제 #21
0
            internal LinuxNetworkInterfaceSystemProperties()
            {
                if (File.Exists(NetworkFiles.Ipv4RouteFile))
                {
                    IPv4Routes = File.ReadAllLines(NetworkFiles.Ipv4RouteFile);
                }

                if (File.Exists(NetworkFiles.Ipv6RouteFile))
                {
                    IPv6Routes = File.ReadAllLines(NetworkFiles.Ipv6RouteFile);
                }

                try
                {
                    string resolverConfig = File.ReadAllText(NetworkFiles.EtcResolvConfFile);
                    DnsSuffix    = StringParsingHelpers.ParseDnsSuffixFromResolvConfFile(resolverConfig);
                    DnsAddresses = new InternalIPAddressCollection(StringParsingHelpers.ParseDnsAddressesFromResolvConfFile(resolverConfig));
                }
                catch (FileNotFoundException)
                {
                }
            }
 internal SystemIPInterfaceProperties(FixedInfo fixedInfo, IpAdapterInfo ipAdapterInfo)
 {
     this.dnsEnabled         = fixedInfo.EnableDns;
     this.name               = ipAdapterInfo.adapterName;
     this.index              = ipAdapterInfo.index;
     this.multicastAddresses = new MulticastIPAddressInformationCollection();
     this.anycastAddresses   = new IPAddressInformationCollection();
     if (this.index > 0)
     {
         this.versionSupported |= IPVersion.IPv4;
     }
     if (ComNetOS.IsWin2K)
     {
         this.ReadRegDnsSuffix();
     }
     this.unicastAddresses = new UnicastIPAddressInformationCollection();
     foreach (IPExtendedAddress address in ipAdapterInfo.ipAddressList.ToIPExtendedAddressArrayList())
     {
         this.unicastAddresses.InternalAdd(new SystemUnicastIPAddressInformation(ipAdapterInfo, address));
     }
     try
     {
         this.ipv4Properties = new SystemIPv4InterfaceProperties(fixedInfo, ipAdapterInfo);
         if ((this.dnsAddresses == null) || (this.dnsAddresses.Count == 0))
         {
             this.dnsAddresses = this.ipv4Properties.DnsAddresses;
         }
     }
     catch (NetworkInformationException exception)
     {
         if (exception.ErrorCode != 0x57L)
         {
             throw;
         }
     }
 }
 public UnixIPInterfaceProperties(UnixNetworkInterface uni)
 {
     _uni          = uni;
     _dnsSuffix    = GetDnsSuffix();
     _dnsAddresses = GetDnsAddresses();
 }
        internal static GatewayIPAddressInformationCollection ToGatewayIpAddressInformationCollection(IPAddressCollection addresses)
        {
            GatewayIPAddressInformationCollection gatewayList = new GatewayIPAddressInformationCollection();

            foreach (IPAddress address in addresses)
            {
                gatewayList.InternalAdd(new SystemGatewayIPAddressInformation(address));
            }
            return(gatewayList);
        }
예제 #25
0
 internal FixedInfo(FIXED_INFO info)
 {
     this.info         = info;
     this.dnsAddresses = info.DnsServerList.ToIPAddressCollection();
 }