source: trunk/i2p/onioncat-privatehosts.pl @ 534

Revision 534, 1.5 KB checked in by eagle, 2 years ago (diff)

merged GarliCat branch back into trunk
onioncat-privatehosts.pl added (code by zzz)

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2#
3# Reads hosts.txt and generates a file which can be used as privatehosts.txt
4# for the I2P router to convert GarliCat-IDs back to the original key.
5#
6# The original hostname, full IPV6 address, and b32 name are included as a
7# comment for each host.
8#
9# See below for perl package requirements.
10#
11# zzz 1/08 public domain
12#
13
14use strict;
15use CGI qw(:standard);
16use MIME::Base64;
17use Convert::Base32;
18use Digest::SHA qw(sha256);
19use Digest::SHA qw(sha256_hex);
20
21my $hosthash;
22
23# load the whole db into memory
24sub loadhosts
25{
26   my $hostcount = 0;
27   open(local *STATLIST, "hosts.txt") or die "Can't access hosts.txt!";
28   while (<STATLIST>) {
29      my $name;
30      my $key;
31      my $restofline;
32      ($name,$restofline) = split(/=/);
33      $key = $restofline;
34      $name = lc($name);
35      chomp($key);
36      $hosthash->{$name} = $key;
37      $hostcount++;
38   }
39   close STATLIST;
40}
41
42
43sub printhosts
44{
45   my @sorted = keys %$hosthash;
46   my $name;
47   foreach $name (@sorted) {
48      my $b64 = $hosthash->{$name};
49      $b64 =~ s/-/+/g;
50      $b64 =~ s/~/\//g;
51      my $decoded = decode_base64($b64);
52      my $hash=sha256($decoded);
53      my $hexhash = sha256_hex($decoded);
54      my $encoded = encode_base32($hash);
55      print "#" . $name . " fd60:db4d:ddb5";
56      for (my $i = 0; $i < 20; $i += 4) {
57         printf(":%s", substr($hexhash, $i, 4));
58      }
59      print " " . $encoded . ".b32.i2p\n";
60      print substr($encoded, 0, 16) . ".oc.b32.i2p=" . $hosthash->{$name} . "\n";
61   }
62   return 0;
63}
64
65loadhosts();
66printhosts();
67
Note: See TracBrowser for help on using the repository browser.