根据https://docs.ar-soft.de/arsoft.tools.net/上的 arsoft.tools.net 文档,我们刚刚开发了一个 dns 服务器来拦截来自网络的每个请求,一切正常!
让我们慢下来的事情是:当客户端键入 www.google.com(例如)时,我们想要显示或重定向到 www.yahoo.com(或 IP 地址),我们如何实现这一点的任何线索?
有些人在这里寻找相同的解决方案: https ://arsofttoolsnet.codeplex.com/discussions?searchText=redirect
Tks
更新 1:
到目前为止,这就是我所拥有的,但是重定向不起作用:
class Program
{
static void Main(string[] args)
{
using (DnsServer server = new DnsServer(System.Net.IPAddress.Any, 10, 10))
{
server.QueryReceived += OnQueryReceived;
server.Start();
Console.WriteLine("Press any key to stop server");
Console.ReadLine();
}
}
static async Task OnQueryReceived(object sender, QueryReceivedEventArgs e)
{
DnsMessage query = e.Query as DnsMessage;
if (query == null)
return;
DnsMessage response = query.CreateResponseInstance();
//response.AnswerRecords.Clear();
//response.AdditionalRecords.Clear();
if ((response.Questions.Count == 1))
{
// send query to upstream server
DnsQuestion question = response.Questions[0];
if (question.Name.ToString().Contains("www.google.com"))
{
DnsMessage upstreamResponse = await DnsClient.Default.ResolveAsync(DomainName.Parse("www.yahoo.com"), question.RecordType, question.RecordClass);
//DnsMessage upstreamResponse = await DnsClient.Default.ResolveAsync(question.Name, question.RecordType, question.RecordClass);
foreach (DnsRecordBase record in (upstreamResponse.AnswerRecords))
{
response.AnswerRecords.Add(record);
}
foreach (DnsRecordBase record in (upstreamResponse.AdditionalRecords))
{
response.AdditionalRecords.Add(record);
}
response.ReturnCode = ReturnCode.NoError;
e.Response = response;
}
}
}
}