Commit 268a39fb authored by Barry Warsaw's avatar Barry Warsaw

converted to python

parent f1945466
#! /depot/gnu/plat/bin/perl #! /depot/sundry/plat/bin/python
# #
# Note: you may have to edit the top line in this file. # Note: you may have to edit the top line in this file.
# #
...@@ -14,133 +14,132 @@ ...@@ -14,133 +14,132 @@
# the speed in which political boundaries are changing these days, no # the speed in which political boundaries are changing these days, no
# doubt there are some incorrect mappings. # doubt there are some incorrect mappings.
$prog = $0; import sys
$ARGV[0] || die "No addresses provided.\nUsage: $prog addr1 [addr2 ...]\n"; prog = sys.argv[0]
del sys.argv[0]
if not sys.argv:
print "No addresses provided.\nUsage:", prog, "addr1 [addr2 ...]\n"
# The mappings # The mappings
%nameorg = ( nameorg = {
"arpa", "Arpanet", "arpa": "Arpanet",
'com', 'commercial', "com": "commercial",
'edu', 'educational', "edu": "educational",
'gov', 'government', "gov": "government",
'mil', 'military', "mil": "military",
'net', 'networking', "net": "networking",
'org', 'non-commercial', "org": "non-commercial",
'int', 'international' "int": "international"
); }
%country = ( country = {
"ag", "Antigua and Barbuda", "ag": "Antigua and Barbuda",
"al", "Albania", "al": "Albania",
"aq", "Antarctica", "aq": "Antarctica",
"ar", "Argentina", "ar": "Argentina",
"at", "Austria", "at": "Austria",
"au", "Australia", "au": "Australia",
"bb", "Barbados", "bb": "Barbados",
"be", "Belgium", "be": "Belgium",
"bg", "Bulgaria", "bg": "Bulgaria",
"bo", "Bolivia", "bo": "Bolivia",
"br", "Brazil", "br": "Brazil",
"bs", "Bahamas", "bs": "Bahamas",
"bz", "Belize", "bz": "Belize",
"ca", "Canada", "ca": "Canada",
"ch", "Switzerland", "ch": "Switzerland",
"cl", "Chile", "cl": "Chile",
"cm", "Cameroon", "cm": "Cameroon",
"cn", "China", "cn": "China",
"co", "Colombia", "co": "Colombia",
"cr", "Costa Rica", "cr": "Costa Rica",
"cy", "Cyprus", "cy": "Cyprus",
"cz", "Czech Republic", "cz": "Czech Republic",
"de", "Germany", "de": "Germany",
"dk", "Denmark", "dk": "Denmark",
"dm", "Dominica", "dm": "Dominica",
"do", "Dominican Republic", "do": "Dominican Republic",
"ec", "Ecuador", "ec": "Ecuador",
"ee", "Estonia", "ee": "Estonia",
"eg", "Egypt", "eg": "Egypt",
"es", "Spain", "es": "Spain",
"fi", "Finland", "fi": "Finland",
"fj", "Fiji", "fj": "Fiji",
"fr", "France", "fr": "France",
"gb", "Great Britain", "gb": "Great Britain",
"gh", "Ghana", "gh": "Ghana",
"gr", "Greece", "gr": "Greece",
"hk", "Hong Kong", "hk": "Hong Kong",
"hr", "Croatia", "hr": "Croatia",
"hu", "Hungary", "hu": "Hungary",
"id", "Indonesia", "id": "Indonesia",
"ie", "Ireland", "ie": "Ireland",
"il", "Israel", "il": "Israel",
"in", "India", "in": "India",
"is", "Iceland", "is": "Iceland",
"it", "Italy", "it": "Italy",
"jm", "Jamaica", "jm": "Jamaica",
"jp", "Japan", "jp": "Japan",
"km", "Comoros", "km": "Comoros",
"kn", "Saint Kitts and Nevis", "kn": "Saint Kitts and Nevis",
"kr", "Republic of Korea", "kr": "Republic of Korea",
"kw", "Kuwait", "kw": "Kuwait",
"lc", "Saint Lucia", "lc": "Saint Lucia",
"li", "Liechtenstein", "li": "Liechtenstein",
"lk", "Sri Lanka", "lk": "Sri Lanka",
"lu", "Luxembourg", "lu": "Luxembourg",
"lv", "Latvia", "lv": "Latvia",
"my", "Malaysia", "my": "Malaysia",
"mx", "Mexico", "mx": "Mexico",
"na", "Namibia", "na": "Namibia",
"ni", "Nicaragua", "ni": "Nicaragua",
"nl", "Netherlands", "nl": "Netherlands",
"no", "Norway", "no": "Norway",
"nz", "New Zealand", "nz": "New Zealand",
"pe", "Peru", "pe": "Peru",
"pg", "Papua New Guinea", "pg": "Papua New Guinea",
"ph", "Philippines", "ph": "Philippines",
"pl", "Poland", "pl": "Poland",
"pr", "Puerto Rico", "pr": "Puerto Rico",
"pt", "Portugal", "pt": "Portugal",
"py", "Paraguay", "py": "Paraguay",
"ro", "Romania", "ro": "Romania",
"se", "Sweden", "se": "Sweden",
"sg", "Singapore", "sg": "Singapore",
"si", "Slovenia", "si": "Slovenia",
"sk", "Slovakia", "sk": "Slovakia",
"sr", "Suriname", "sr": "Suriname",
"su", "USSR", "su": "USSR",
"tw", "Taiwan", "tw": "Taiwan",
"th", "Thailand", "th": "Thailand",
"tn", "Tunisia", "tn": "Tunisia",
"tr", "Turkey", "tr": "Turkey",
"tt", "Trinidad and Tobago", "tt": "Trinidad and Tobago",
"uk", "United Kingdom", "uk": "United Kingdom",
"us", "United States", "us": "United States",
"uy", "Uruguay", "uy": "Uruguay",
"vc", "Saint Vincent and the Grenadines", "vc": "Saint Vincent and the Grenadines",
"ve", "Venezuela", "ve": "Venezuela",
"vi", "Virgin Islands", "vi": "Virgin Islands",
"yu", "Yugoslavia", "yu": "Yugoslavia",
"za", "South Africa", "za": "South Africa",
"zw", "Zimbabwe" "zw": "Zimbabwe"
); }
import string
while ($addr = shift @ARGV) {
($_) = $addr =~ /\.(.*)$/;
$_ = $addr if !$_;
if ($nameorg{$_}) { while sys.argv:
# its one of the `special' USA organizational domains rawaddr = sys.argv[0]
print "$addr is from a USA $nameorg{$_} organization\n"; del sys.argv[0]
}
elsif ($country{$_}) { components = string.splitfields(rawaddr, ".")
# its a country code addr = components[-1]
print "$addr originated from $country{$_}\n";
} if nameorg.has_key(addr):
else { print addr, "is from a USA", nameorg[addr], "organization"
# who knows? elif country.has_key(addr):
print "I have no idea where $addr came from!\n"; print addr, "originated from", country[addr]
} else:
} print "I have no idea where", addr, "came from!"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment