-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDns.cs
79 lines (69 loc) · 1.39 KB
/
Dns.cs
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using MikuBot.Commands;
using MikuBot.Modules;
namespace MikuBot.ExtraPlugins
{
public class DnsResolve : MsgCommandModuleBase
{
public override int BotCommandParamCount
{
get { return 1; }
}
public override string CommandDescription
{
get { return "Resolves DNS address"; }
}
public override string Name
{
get { return "Dns"; }
}
public override string UsageHelp
{
get { return "dns <url>"; }
}
public override void HandleCommand(MsgCommand chat, IBotContext bot)
{
if (!CheckCall(chat, bot))
return;
var reply = chat.Reply(bot.Writer);
var param = chat.BotCommand.Params[0];
string host;
try
{
var u = new Uri(param);
host = u.DnsSafeHost;
}
catch (UriFormatException)
{
host = param;
}
IPAddress[] addresses;
try
{
addresses = Dns.GetHostAddresses(host);
}
catch (ArgumentException x)
{
reply.Msg("DNS (error): " + x.Message);
return;
}
catch (SocketException x)
{
reply.Msg("DNS (error): " + x.Message);
return;
}
if (!addresses.Any())
{
reply.Msg("DNS: Nothing found.");
return;
}
var addressStr = addresses.Select(a => a.ToString());
reply.Msg("Addresses for " + host + ": " + string.Join(", ", addressStr));
}
}
}