Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 268a39f

Browse files
committed
converted to python
1 parent f194546 commit 268a39f

1 file changed

Lines changed: 123 additions & 124 deletions

File tree

Tools/world/world

Lines changed: 123 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /depot/gnu/plat/bin/perl
1+
#! /depot/sundry/plat/bin/python
22
#
33
# Note: you may have to edit the top line in this file.
44
#
@@ -14,133 +14,132 @@
1414
# the speed in which political boundaries are changing these days, no
1515
# doubt there are some incorrect mappings.
1616

17-
$prog = $0;
18-
$ARGV[0] || die "No addresses provided.\nUsage: $prog addr1 [addr2 ...]\n";
17+
import sys
18+
prog = sys.argv[0]
19+
del sys.argv[0]
20+
if not sys.argv:
21+
print "No addresses provided.\nUsage:", prog, "addr1 [addr2 ...]\n"
1922

2023

21-
2224
# 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'
32-
);
25+
nameorg = {
26+
"arpa": "Arpanet",
27+
"com": "commercial",
28+
"edu": "educational",
29+
"gov": "government",
30+
"mil": "military",
31+
"net": "networking",
32+
"org": "non-commercial",
33+
"int": "international"
34+
}
3335

3436

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"
127-
);
37+
country = {
38+
"ag": "Antigua and Barbuda",
39+
"al": "Albania",
40+
"aq": "Antarctica",
41+
"ar": "Argentina",
42+
"at": "Austria",
43+
"au": "Australia",
44+
"bb": "Barbados",
45+
"be": "Belgium",
46+
"bg": "Bulgaria",
47+
"bo": "Bolivia",
48+
"br": "Brazil",
49+
"bs": "Bahamas",
50+
"bz": "Belize",
51+
"ca": "Canada",
52+
"ch": "Switzerland",
53+
"cl": "Chile",
54+
"cm": "Cameroon",
55+
"cn": "China",
56+
"co": "Colombia",
57+
"cr": "Costa Rica",
58+
"cy": "Cyprus",
59+
"cz": "Czech Republic",
60+
"de": "Germany",
61+
"dk": "Denmark",
62+
"dm": "Dominica",
63+
"do": "Dominican Republic",
64+
"ec": "Ecuador",
65+
"ee": "Estonia",
66+
"eg": "Egypt",
67+
"es": "Spain",
68+
"fi": "Finland",
69+
"fj": "Fiji",
70+
"fr": "France",
71+
"gb": "Great Britain",
72+
"gh": "Ghana",
73+
"gr": "Greece",
74+
"hk": "Hong Kong",
75+
"hr": "Croatia",
76+
"hu": "Hungary",
77+
"id": "Indonesia",
78+
"ie": "Ireland",
79+
"il": "Israel",
80+
"in": "India",
81+
"is": "Iceland",
82+
"it": "Italy",
83+
"jm": "Jamaica",
84+
"jp": "Japan",
85+
"km": "Comoros",
86+
"kn": "Saint Kitts and Nevis",
87+
"kr": "Republic of Korea",
88+
"kw": "Kuwait",
89+
"lc": "Saint Lucia",
90+
"li": "Liechtenstein",
91+
"lk": "Sri Lanka",
92+
"lu": "Luxembourg",
93+
"lv": "Latvia",
94+
"my": "Malaysia",
95+
"mx": "Mexico",
96+
"na": "Namibia",
97+
"ni": "Nicaragua",
98+
"nl": "Netherlands",
99+
"no": "Norway",
100+
"nz": "New Zealand",
101+
"pe": "Peru",
102+
"pg": "Papua New Guinea",
103+
"ph": "Philippines",
104+
"pl": "Poland",
105+
"pr": "Puerto Rico",
106+
"pt": "Portugal",
107+
"py": "Paraguay",
108+
"ro": "Romania",
109+
"se": "Sweden",
110+
"sg": "Singapore",
111+
"si": "Slovenia",
112+
"sk": "Slovakia",
113+
"sr": "Suriname",
114+
"su": "USSR",
115+
"tw": "Taiwan",
116+
"th": "Thailand",
117+
"tn": "Tunisia",
118+
"tr": "Turkey",
119+
"tt": "Trinidad and Tobago",
120+
"uk": "United Kingdom",
121+
"us": "United States",
122+
"uy": "Uruguay",
123+
"vc": "Saint Vincent and the Grenadines",
124+
"ve": "Venezuela",
125+
"vi": "Virgin Islands",
126+
"yu": "Yugoslavia",
127+
"za": "South Africa",
128+
"zw": "Zimbabwe"
129+
}
128130

129-
130-
while ($addr = shift @ARGV) {
131-
($_) = $addr =~ /\.(.*)$/;
132-
$_ = $addr if !$_;
131+
import string
133132

134-
if ($nameorg{$_}) {
135-
# its one of the `special' USA organizational domains
136-
print "$addr is from a USA $nameorg{$_} organization\n";
137-
}
138-
elsif ($country{$_}) {
139-
# its a country code
140-
print "$addr originated from $country{$_}\n";
141-
}
142-
else {
143-
# who knows?
144-
print "I have no idea where $addr came from!\n";
145-
}
146-
}
133+
while sys.argv:
134+
rawaddr = sys.argv[0]
135+
del sys.argv[0]
136+
137+
components = string.splitfields(rawaddr, ".")
138+
addr = components[-1]
139+
140+
if nameorg.has_key(addr):
141+
print addr, "is from a USA", nameorg[addr], "organization"
142+
elif country.has_key(addr):
143+
print addr, "originated from", country[addr]
144+
else:
145+
print "I have no idea where", addr, "came from!"

0 commit comments

Comments
 (0)