changes by Barry, e.g. font lock & email addresses
[python/dscho.git] / Tools / world / world
blob7491708773c031a49b23feef0ddb63b12f3a91ea
1 #! /depot/sundry/plat/bin/python
3 # Note: you may have to edit the top line in this file.
5 # Usage: world addr1 [addr2 ...]
7 # $Id$
9 # This little script will take an Internet address of the form
10 # foobar@some.place.domain and will print out where in the world that
11 # message originated from. Its pretty dumb in that it just matches
12 # the `domain' part against a hard-coded list, which can probably
13 # change fairly quickly given the world's political fluidity.
15 import sys
16 prog = sys.argv[0]
17 del sys.argv[0]
18 if not sys.argv:
19 print "No addresses provided.\nUsage:", prog, "addr1 [addr2 ...]\n"
22 # The mappings
23 nameorg = {
24 "arpa": "Arpanet",
25 "com": "commercial",
26 "edu": "educational",
27 "gov": "government",
28 "mil": "military",
29 "net": "networking",
30 "org": "non-commercial",
31 "int": "international"
35 country = {
36 "ag": "Antigua and Barbuda",
37 "al": "Albania",
38 "aq": "Antarctica",
39 "ar": "Argentina",
40 "at": "Austria",
41 "au": "Australia",
42 "bb": "Barbados",
43 "be": "Belgium",
44 "bg": "Bulgaria",
45 "bo": "Bolivia",
46 "br": "Brazil",
47 "bs": "Bahamas",
48 "bz": "Belize",
49 "ca": "Canada",
50 "ch": "Switzerland",
51 "cl": "Chile",
52 "cm": "Cameroon",
53 "cn": "China",
54 "co": "Colombia",
55 "cr": "Costa Rica",
56 "cy": "Cyprus",
57 "cz": "Czech Republic",
58 "de": "Germany",
59 "dk": "Denmark",
60 "dm": "Dominica",
61 "do": "Dominican Republic",
62 "ec": "Ecuador",
63 "ee": "Estonia",
64 "eg": "Egypt",
65 "es": "Spain",
66 "fi": "Finland",
67 "fj": "Fiji",
68 "fr": "France",
69 "gb": "Great Britain",
70 "gh": "Ghana",
71 "gr": "Greece",
72 "hk": "Hong Kong",
73 "hr": "Croatia",
74 "hu": "Hungary",
75 "id": "Indonesia",
76 "ie": "Ireland",
77 "il": "Israel",
78 "in": "India",
79 "is": "Iceland",
80 "it": "Italy",
81 "jm": "Jamaica",
82 "jp": "Japan",
83 "km": "Comoros",
84 "kn": "Saint Kitts and Nevis",
85 "kr": "Republic of Korea",
86 "kw": "Kuwait",
87 "lc": "Saint Lucia",
88 "li": "Liechtenstein",
89 "lk": "Sri Lanka",
90 "lu": "Luxembourg",
91 "lv": "Latvia",
92 "my": "Malaysia",
93 "mx": "Mexico",
94 "na": "Namibia",
95 "ni": "Nicaragua",
96 "nl": "Netherlands",
97 "no": "Norway",
98 "nz": "New Zealand",
99 "pe": "Peru",
100 "pg": "Papua New Guinea",
101 "ph": "Philippines",
102 "pl": "Poland",
103 "pr": "Puerto Rico",
104 "pt": "Portugal",
105 "py": "Paraguay",
106 "ro": "Romania",
107 "se": "Sweden",
108 "sg": "Singapore",
109 "si": "Slovenia",
110 "sk": "Slovakia",
111 "sr": "Suriname",
112 "su": "USSR",
113 "tw": "Taiwan",
114 "th": "Thailand",
115 "tn": "Tunisia",
116 "tr": "Turkey",
117 "tt": "Trinidad and Tobago",
118 "uk": "United Kingdom",
119 "us": "United States",
120 "uy": "Uruguay",
121 "vc": "Saint Vincent and the Grenadines",
122 "ve": "Venezuela",
123 "vi": "Virgin Islands",
124 "yu": "Yugoslavia",
125 "za": "South Africa",
126 "zw": "Zimbabwe"
129 import string
131 while sys.argv:
132 rawaddr = sys.argv[0]
133 del sys.argv[0]
135 components = string.splitfields(rawaddr, ".")
136 addr = components[-1]
138 if nameorg.has_key(addr):
139 print addr, "is from a USA", nameorg[addr], "organization"
140 elif country.has_key(addr):
141 print addr, "originated from", country[addr]
142 else:
143 print "I have no idea where", addr, "came from!"