Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote a block of code that reads the byte stream from the browser on UDP/53 and sends this to a DNS server and gets a valid result back but when I send this byte stream back to the browers using UDP packets on the remote endpoint use to make the original request the browser simply sends the request back again and yet calling the code from a socket works fine.

The reason I need this code is because BT Home are sending back fake DNS results in the UK and this allows site to bypass IP address that I have banned in the firewall.
C#
public void Listen()
{
receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp );
receiveEndPoint = new IPEndPoint(IPAddress.Any, receivePort); receiveSocket.Bind(receiveEndPoint); 
receivePort = (receiveSocket.LocalEndPoint as IPEndPoint).Port; 
receiveBuffer = new byte[BufferSize]; 
receiveAsyncResult = receiveSocket.BeginReceiveFrom(receiveBuffer, 0, receiveBuffer.Length, SocketFlags.None, ref receiveEndPoint, new AsyncCallback(NetworkMessageReceivedCallback), receiveSocket);
}
public void NetworkMessageReceivedCallback(IAsyncResult asyncResult)
{
EndPoint remoteEndPoint = null; 
byte[] bytes = null; 
remoteEndPoint = new IPEndPoint(IPAddress.Any, 0); //Will contain the clients port 
int bytesRead = receiveSocket.EndReceiveFrom(asyncResult, ref remoteEndPoint); 
bytes = new Byte[bytesRead]; 
Buffer.BlockCopy(receiveBuffer, 0, bytes, 0, bytesRead);
//string ip = "208.67.222.222";
string ip = "192.168.1.254";
IPAddress dnsServer = IPAddress.Parse(ip);
Response R = Resolver.Lookup(bytes, dnsServer);
receiveSocket.SendTo(R.Message , remoteEndPoint);//127.0.0.1
receiveSocket.Close();
Listen();
}
Posted
Updated 12-Oct-10 3:23am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900