Link to home
Start Free TrialLog in
Avatar of carlostriassi
carlostriassiFlag for United States of America

asked on

Convert IP address to DNS value it is slow scanning 254 devices

I'm able to ping 254 devices and get result back for their round trip time between 3-4 seconds. I'm using ThreadPool and it works great.
I have collected all devices IP addresses and keeping records of those that have gotten a round trip values and those that have failed; so I can filter out the IP address that never got back their round trip from ping.
Given a collection of set good IP address; I can collect DNS values for each IP address; I have used everything but it takes 45 secods to over 1 minute to get back some DNS values from those set of good IP addresses.

I have use this code; this is very slooooow

 IPHostEntry ipHostEntry = Dns.GetHostByAddress(IPAddress.Parse(IP));

then I use this code below; it is better at best using ThreadPool but nevertheless it takes 45 secods to 1+ minute.      

        private delegate IPHostEntry GetHostEntryHandler(string ip);
        public string ReverseDNS(string ip, int timeout) // timeout in milliseconds
        {
            try
            {
                GetHostEntryHandler callback = new GetHostEntryHandler(Dns.GetHostEntry);
                IAsyncResult result = callback.BeginInvoke(ip, null, null);
                if (result.AsyncWaitHandle.WaitOne(timeout, false))
                {
                    // Received response within timeout limit
                    return callback.EndInvoke(result).HostName;
                }
                else
                {
                    // Did not receive response within timeout limit,
                    // send back IP Address instead of hostname
                    return ip;
                }
            }
            catch (Exception)
            {
                // Error occurred, send back IP Address instead of hostname
                return ip;
            }
        }
 
I run a comparison to a tool that I found Si360 scanning the same 254 devices as on my test program; SI260 took 9 seconds to get response back resolve all DNS values whenever possible.

Is it anything that I'm missing to get a faster response on converting IP address to DNS.

Your help would be much appreciated.

Regards
Calos.




ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of carlostriassi

ASKER

great job and thank you!