forked from Efreak/ZNC-Modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns.cpp
70 lines (58 loc) · 2.04 KB
/
dns.cpp
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
/*
* Copyright (C) 2010 Efreak.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*
* If any other changes are made, update the version number to the latest ZNC
* version to reflect it, please. This makes things easier to know what
* version it works with; If you want to contribute code, let me know via IRC
* and I'll ad you as a contributor on GitHub.
* -Efreak
*/
#include "User.h"
#include "IRCSock.h"
#include "znc.h"
#include <stdio.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
using std::map;
class CDNSMod : public CGlobalModule {
public:
GLOBALMODCONSTRUCTOR(CDNSMod) {}
virtual ~CDNSMod() {}
virtual void OnModCommand(const CString& sLine) {
CString sCommand = sLine.Token(0).AsLower();
CString tk2 = sLine.Token(1).AsLower();
/*
* DNS Resolution
*/
if(sCommand=="dns"||sCommand=="resolve") {
hostent * record = gethostbyname(tk2.c_str());
if(record == NULL) {
PutModule(tk2 + "%s is unavailable.");
} else {
in_addr * address = (in_addr * )record->h_addr;
CString ip_address = CString(inet_ntoa(* address));
PutModule(tk2 + " resolves to: " + ip_address + ".");
}
}
/*
* Help command (todo: implement token-based help)
*/
else if (sCommand == "help") {
PutModule("DNS: This module includes a DNS resolver. Usage: dns/resolve hostname Ex: dns localhost");
PutModule(" message. Prefix defaults to 'ZNC Global Message: ', and can be changed by the arguments.");
// PutModule("ToDo: allow this module to override znc's dns resolution to deny users access to specific servers (can this be done?")
// PutModule("1.0 - initial version");
// PutModule("2.0 - changed around resolve code to fix a crashing error when host doesnt resolve");
PutModule("0.01 - changed version number to a different scheme");
}
}
protected:
private:
};
GLOBALMODULEDEFS(CDNSMod, "DNS Resolver. Version 0.01");