addAll.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python3
  2. # This script will generate somethings you just have to copy in your cjdroute.conf containing all the nodes
  3. # You just have to copy the output in to connectTo
  4. # Without flag you can pass an ip (6 or 4) wich is your, it will be excludede from the list
  5. # If no argument was given it will output for ipv4 and if -6 is given it will run for ipv6
  6. from os.path import exists, isfile
  7. from os import listdir
  8. from json import dumps, loads
  9. from sys import exit, stdout, stderr, argv
  10. arg = argv
  11. global isIPV4
  12. isIPV4 = not "-6" in arg
  13. if not isIPV4:
  14. arg.remove("-6")
  15. global yourIP
  16. if len(arg) == 1:
  17. yourIP = arg[0]
  18. else:
  19. yourIP = ""
  20. global nodes_list
  21. nodes_list = {}
  22. def search(path):
  23. global nodes_list
  24. global isIPV4
  25. global yourIP
  26. for i in listdir(path):
  27. thing = path + "/" + i
  28. if isfile(thing):
  29. try:
  30. with open(thing, "r") as f:
  31. for k, v in loads(f.read()).items():
  32. # If ip format is the same as requested.
  33. if ("." in k) is isIPV4 and k.split(":")[0] is not yourIP:
  34. node = {
  35. "password": v["password"],
  36. "publicKey": v["publicKey"],
  37. "contact": v["contact"]
  38. }
  39. try:
  40. node["login"] = v["login"]
  41. except:
  42. pass
  43. nodes_list[k] = node
  44. except Exception:
  45. stderr.write("Got an error while reading : " + thing + "\n")
  46. else:
  47. search(thing)
  48. for i in ["as","sa","na","af","eu","an","oc"]:
  49. if exists(i):
  50. search(i)
  51. stdout.write("".join(list(dumps(nodes_list))[1:-1]) + "\n")
  52. exit(1)