guard_country_resolver.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import sys
  2. if sys.version_info[0] == 2:
  3. input = raw_input
  4. # Five eye countries and Israel
  5. FIVE_EYES_I = ['us','ca','gb','nz','au','il']
  6. # This excludes US because a lot of exit trafic goes to the us anyways and this should also help reduce distinguishability.
  7. FOUR_EYES_I = ['ca','gb','nz','au','il']
  8. # America and their guards
  9. AMERICA_S = ['ar','bo','br','cl','co','ec','gf','gy','py','pe','sr','uy','ve']
  10. AMERICA_C = ['mx','cu','ht','dm','jm','pa','gt','hn','ni','cr','bs','bz']
  11. AMERICA_TARGETS = AMERICA_S + ['pt','es','za']
  12. # Maghreb countries and close european countries as guards
  13. MAGHREB = ['ml', 'mr', 'eh', 'ma', 'dz', 'tn', 'ly']
  14. MAGHREB_TARGETS = ['pt','es','fr','it','gr']
  15. # South east asia.
  16. SEA = ['jp', 'kr', 'tw', 'hk', 'sg', 'vn']
  17. # European peninsula countries
  18. EUROPEAN_TARGETS = MAGHREB_TARGETS + ['de','nl','ch','se', 'dk','be','lu','at','cz','pl','ro','lv', 'ee','lt','no','ua','ru','si','sk','hr','rs','bg', 'hu', 'fi','md','pl']
  19. # Basically all countries with relays, omitting FIVE_EYES_I
  20. OTHERS_TARGETS = EUROPEAN_TARGETS + AMERICA_S + SEA
  21. # Profiles for larger Tor countries:
  22. guard_resolver = dict([
  23. ( 'de' , ['de', 'nl', 'lu', 'ch', 'pl', 'dk'] ),
  24. ( 'ch' , ['ch', 'de', 'fr','it','at'] ),
  25. ( 'at' , ['at','it','ch','de','cz','hu','si','sk'] ),
  26. ( 'cz' , ['cz','de','pl','at','sk'] ),
  27. ( 'pl' , ['pl', 'de', 'cz','si','ua'] ),
  28. ( 'dk' , ['dk','de','se','no','is'] ),
  29. ( 'se' , ['se', 'no', 'dk','fi','is'] ),
  30. ( 'nl' , ['nl', 'be','de','lu','fr'] ),
  31. ( 'be' , ['be', 'fr', 'nl', 'lu','de'] ),
  32. ( 'lu' , ['lu','nl','be','fr','de'] ),
  33. ( 'fr' , ['fr', 'es','ch','be'] ),
  34. ( 'gb' , ['gb', 'ie', 'fr','be','nl'] ),
  35. ( 'uk' , ['gb', 'ie', 'fr','be','nl'] ),
  36. ( 'us' , ['us', 'ca'] ),
  37. ( 'ca' , ['ca', 'us'] ),
  38. ( 'il' , ['il', 'tr', 'gr', 'it', 'ro','ua','ru'] ),
  39. ( 'au' , ['au', 'nz'] + SEA ),
  40. ( 'nz' , ['au', 'nz'] + SEA ),
  41. ( 'ro' , ['ro','md','ua','tr','hu'] ),
  42. ( 'ru' , ['ru', 'no', 'lv', 'ee', 'lt', 'ua'] ),
  43. ( 'lv' , ['ru', 'lv', 'ee', 'lt'] ),
  44. ( 'ee' , ['ru', 'lv', 'ee', 'lt'] ),
  45. ( 'lt' , ['ru', 'lv', 'ee', 'lt'] ),
  46. ( 'it' , ['it','fr','gr','ch','at','hr','si'] ),
  47. ( 'ua' , ['ua', 'ro', 'md','pl','ru'] ),
  48. ( 'md' , ['ua', 'ro', 'md'] ),
  49. ( 'gr' , ['gr', 'it', 'tr', 'hr', 'ro'] ),
  50. ( 'pt' , ['pt', 'es', 'fr'] ),
  51. ( 'es' , ['pt', 'es', 'fr'] ),
  52. ( 'tr' , ['tr', 'gr', 'it', 'ro','ua','ru'] ),
  53. ( 'hu' , ['hu', 'at', 'cz', 'pt', 'ro'] ),
  54. ( 'is' , ['is', 'dk','no','se'] ),
  55. ( 'no' , ['no', 'dk','se','is'] ),
  56. ( 'africa' , EUROPEAN_TARGETS + ['za'] ),
  57. ( 'southeastasia' , SEA + ['ru']),
  58. ( 'america' , AMERICA_TARGETS ),
  59. ( 'europe' , EUROPEAN_TARGETS ),
  60. ( 'other' , OTHERS_TARGETS )
  61. ])
  62. #
  63. # Regions that guard each other:
  64. #
  65. for country in SEA:
  66. guard_resolver[country] = SEA + ['ru']
  67. for country in AMERICA_S:
  68. guard_resolver[country] = AMERICA_TARGETS
  69. for country in AMERICA_C:
  70. guard_resolver[country] = AMERICA_TARGETS + [country]
  71. for country in MAGHREB:
  72. guard_resolver[country] = MAGHREB_TARGETS + [country]
  73. def guards_close_to_home(resolver=guard_resolver):
  74. country_code = input("\nWhat is your two letter country code?\n").lower()
  75. if country_code in resolver:
  76. return resolver[country_code], country_code
  77. else:
  78. print( "\nCountry code '" + country_code + "' not known." )
  79. print( "Try other code or one of the general regions:" )
  80. print( "africa, southeastasia, america, europe, other" )
  81. return guards_close_to_home(resolver)
  82. if __name__=="__main__":
  83. # This is used only during development
  84. print( guards_close_to_home() )