在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;
}
}
}
}
答案 0 :(得分:3)
过了一段时间,这是怎么做的:
dir /B [startpath]
如果你想指向某个IP地址:
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();
DnsQuestion question = response.Questions[0];
DnsMessage upstreamResponse = await DnsClient.Default.ResolveAsync(!question.Name.ToString().Contains("www.google.com") ? question.Name : DomainName.Parse("www.yahoo.com"), 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;
}
}