Browse Source

Merge pull request #5 from majestrate/master

add routerinfo tool
pull/7/head
Jeff 8 years ago committed by GitHub
parent
commit
2d719de2b6
  1. 5
      Makefile
  2. 15
      README.md
  3. 2
      i2pd
  4. 92
      routerinfo.cpp

5
Makefile

@ -11,7 +11,10 @@ OBJECTS = $(SOURCES:.cpp=.o) @@ -11,7 +11,10 @@ OBJECTS = $(SOURCES:.cpp=.o)
I2PD_LIB = libi2pd.a
all: keygen keyinfo famtool
all: keygen keyinfo famtool routerinfo
routerinfo: $(OBJECTS)
$(CXX) -o routerinfo routerinfo.o $(LDFLAGS) $(LIBS)
keygen: $(OBJECTS)
$(CXX) -o keygen keygen.o $(LDFLAGS) $(LIBS)

15
README.md

@ -42,6 +42,21 @@ i2p netdb blocklist generator tool @@ -42,6 +42,21 @@ i2p netdb blocklist generator tool
see [here](baddiefinder)
### routerinfo
print information about a router info file
#### usage
print ip and port for router info excluding ipv6
./routerinfo -p ~/.i2pd/netDb/r6/routerInfo-blah.dat
print iptables firewall rules to allow 1 nodes in netdb through firewall including ipv6 addresses
./routerinfo -6 -f ~/.i2pd/netDb/r6/routerInfo-blah.dat
### keygen
Generate an i2p private key

2
i2pd

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit 8795f0c8c45a910284c4c6d6e886d4d9ae746ad9
Subproject commit 2767ad75ffbda35856c2dffd930fe1b15d17ac8a

92
routerinfo.cpp

@ -0,0 +1,92 @@ @@ -0,0 +1,92 @@
#include <iostream>
#include <unistd.h>
#include "Crypto.h"
#include "RouterInfo.h"
static void usage(const char * argv)
{
std::cout << "usage: " << argv << " [-6|-f|-p] routerinfo.dat" << std::endl;
}
template<typename Addr>
static void write_firewall_entry(std::ostream & o, Addr addr)
{
std::string proto;
if(addr.transportStyle == i2p::data::RouterInfo::eTransportNTCP) {
proto = "tcp";
} else if (addr.transportStyle == i2p::data::RouterInfo::eTransportSSU) {
proto = "udp";
} else {
// bail
return;
}
o << " -A OUTPUT -p " << proto;
o << " -d " << addr.host << " --dport " << addr.port;
o << " -j ACCEPT";
}
int main(int argc, char * argv[])
{
if (argc < 2) {
usage(argv[0]);
return 1;
}
i2p::crypto::InitCrypto(false);
int opt;
bool ipv6 = false;
bool firewall = false;
bool port = false;
while((opt = getopt(argc, argv, "6fp")) != -1) {
switch(opt) {
case '6':
ipv6 = true;
break;
case 'f':
firewall = true;
break;
case 'p':
port = true;
break;
default:
usage(argv[0]);
return 1;
}
}
while(optind < argc) {
int idx = optind;
optind ++;
std::string fname(argv[idx]);
i2p::data::RouterInfo ri(fname);
std::vector<i2p::data::RouterInfo::Address> addrs;
auto a = ri.GetNTCPAddress(!ipv6);
if(a)
addrs.push_back(*a);
a = ri.GetSSUAddress(!ipv6);
if(a)
addrs.push_back(*a);
if(firewall)
std::cout << "# ";
std::cout << ri.GetIdentHashBase64() << std::endl;
for (const auto & a : addrs) {
if(firewall) {
write_firewall_entry(std::cout, a);
} else {
std::cout << a.host;
if (port)
std::cout << ":" << a.port;
}
std::cout << std::endl;
}
}
return 0;
}
Loading…
Cancel
Save