problem with catching DNS udp packets

May 23 2009 12:25 AM
Hi,
I write a simple program to catch DNS UDP packets which is listening to port 53.

UdpClient server = null;
            try
            {
                server = new UdpClient(0);//also I tried port 53 but same result

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            IPEndPoint remoteip = new IPEndPoint(IPAddress.Any, 0);
            for (; ; )
            {
               
                byte[] bb = server.Receive(ref remoteip);
                Console.WriteLine(Encoding.ASCII.GetString(bb));
               
            }

but it is not showing anything ,to be honest it will stuck in the following line :

                byte[] bb = server.Receive(ref remoteip);

my purpose is to catch my local computer DNS request which are made by several program on my pc then relay their request to real dns servers and then after that cache their relative addresses for later on.
that's why I thought it should be good idea first of all to test DNS:udp53 but no chance.

Answers (1)