findnodes 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python
  2. # You may redistribute this program and/or modify it under the terms of
  3. # the GNU General Public License as published by the Free Software Foundation,
  4. # either version 3 of the License, or (at your option) any later version.
  5. #
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. #
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. import sys;
  14. import os;
  15. from cjdnsadmin.cjdnsadmin import connectWithAdminInfo;
  16. import json;
  17. from pprint import pprint;
  18. from time import sleep;
  19. cjdns = connectWithAdminInfo();
  20. nodes = {};
  21. while (1):
  22. i = 0;
  23. newNodes = [];
  24. while True:
  25. table = cjdns.NodeStore_dumpTable(i);
  26. routes = table['routingTable'];
  27. for entry in routes:
  28. if (not entry['ip'] in nodes):
  29. nodes[entry['ip']] = 1;
  30. newNodes.append(entry);
  31. if (not 'more' in table):
  32. break;
  33. i += 1;
  34. for entry in newNodes:
  35. print json.dumps(entry);
  36. sleep(30);