blendish: cosmetix
[iv.d.git] / btenc_samples / bte_dhtcache_dump.d
blob9e03b5c626cf16b1807f7b6359c2b91d9304315a
1 /* Invisible Vector Library
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 module dumpdht /*is aliced*/;
20 import iv.alice;
21 import iv.btenc;
24 void main () {
25 auto nfo = BTField.load("rtorrent.dht_cache");
26 auto nodes = nfo["/nodes"];
27 foreach (string id; nodes.vdict.byKey) {
28 auto ni = id in nodes.vdict;
29 auto ipnode = "i" in *ni;
30 auto portnode = "p" in *ni;
31 if (ipnode !is null && portnode !is null) {
32 import std.stdio : writefln;
33 uint ip = cast(uint)ipnode.vuint;
34 ushort port = cast(ushort)portnode.vuint;
35 writefln("%s.%s.%s.%s:%s", (ip>>24)&0xff, (ip>>16)&0xff, (ip>>8)&0xff, ip&0xff, port);