-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (52 loc) · 1.96 KB
/
Program.cs
File metadata and controls
61 lines (52 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using ARSoft.Tools.Net.Dns;
using System;
using System.Net;
using System.Net.Sockets;
namespace DNSRootServerResolver
{
public class Program
{
public static void Main(string[] args)
{
using (var server = new DnsServer(IPAddress.Any, 25, 25, DnsServerHandler))
{
server.Start();
string command;
while ((command = Console.ReadLine()) != "exit")
{
if (command == "clear")
{
DNS.GlobalCache.Clear();
}
}
}
}
public static DnsMessageBase DnsServerHandler(DnsMessageBase dnsMessageBase, IPAddress clientAddress, ProtocolType protocolType)
{
DnsMessage query = dnsMessageBase as DnsMessage;
foreach (var question in query.Questions)
{
Console.WriteLine(question);
switch (question.RecordType)
{
case RecordType.A:
case RecordType.Mx:
query.AnswerRecords.AddRange(DNS.Resolve(question.Name, question.RecordType, question.RecordClass)); break;
case RecordType.Ptr:
{
if (question.Name == "1.0.0.127.in-addr.arpa")
{
query.AnswerRecords.Add(new PtrRecord("127.0.0.1", 172800 /*2 days*/, "localhost"));
}
}; break;
default:
{
query.ReturnCode = ReturnCode.NotImplemented;
Console.WriteLine("Unknown record type: " + question.RecordType + " (class: " + question.RecordClass + ", " + question.Name + ")");
} break;
}
}
return query;
}
}
}