BF2Statistics.HostsFile.GetLines C# (CSharp) Method

GetLines() public method

Returns a list of all current hosts file lines
public GetLines ( ) : IPAddress>.Dictionary
return IPAddress>.Dictionary
        public Dictionary<string, IPAddress> GetLines()
        {
            return Entries;
        }

Usage Example

        /// <summary>
        /// Preforms the pings required to fill the dns cache.
        /// The reason we ping, is because once the HOSTS file is locked, any request
        /// made to a url (when the DNS cache is empty), will skip the hosts file, because
        /// it cant be read. If we ping first, then the DNS cache fills up with the IP
        /// addresses in the hosts file.
        /// </summary>
        public static void RebuildDNSCache(CancellationToken CancelToken)
        {
            // Must be hosts file!
            if (RedirectMethod == RedirectMode.DnsServer || !RedirectsEnabled)
            {
                return;
            }

            // Grab hosts file base
            HostsFile hFile = (RedirectMethod == RedirectMode.HostsFile)
                ? HostsFileSys as HostsFile
                : HostsFileIcs as HostsFile;

            // Rebuild the DNS cache with the hosts file redirects
            foreach (string hostname in hFile.GetLines().Keys)
            {
                // Quit on cancel
                if (CancelToken.IsCancellationRequested)
                {
                    return;
                }

                // Only ping gamespy urls with the hosts ics file
                if (RedirectMethod == RedirectMode.HostsIcsFile && !hostname.Contains("gamespy"))
                {
                    continue;
                }

                // Attempt to ping the server
                try
                {
                    // Clear the record from the DNS cache
                    DnsFlushResolverCacheEntry(hostname);

                    // Ping server to get the IP address in the dns cache
                    Dns.GetHostAddresses(hostname);
                }
                catch
                {
                    continue;
                }
            }
        }