html/country.pl


   1 # Print the country name in /WHOIS replies
   2 # /COUNTRY <code> prints the name for the country code
   3 # Installation: Add $whois_country somewhere in your /FORMAT whois line
   4 
   5 use strict;
   6 use Irssi 20021028;
   7 
   8 use vars qw($VERSION %IRSSI);
   9 $VERSION = "1.0.1";
  10 %IRSSI = (
  11 	authors         => "Timo Sirainen",
  12 	contact         => "tss\@iki.fi",
  13 	name            => "country",
  14 	description     => "Print the country name in /WHOIS replies",
  15 	license         => "Public Domain",
  16 	changed         => "Mon Oct 28 00:29:26 EET 2002"
  17 );
  18 
  19 my %countries;
  20 my $last_country = "";
  21 
  22 sub sig_whois {
  23   my ($server, $data, $nick, $host) = @_;
  24   my ($me, $nick, $user, $host) = split(" ", $data);
  25   
  26   if ($host =~ /\.([a-zA-Z]+)$/) {
  27     $last_country = $countries{lc $1};
  28   } else {
  29     $last_country = "";
  30   }
  31 }
  32 
  33 sub expando_whois_country {
  34   return $last_country;
  35 }
  36 
  37 sub cmd_country {
  38   my $country = lc shift;
  39   if ($country eq "") {
  40     Irssi::print("USAGE: /COUNTRY <country code>");
  41     return;
  42   }
  43 
  44   my $name = $countries{$country};
  45   if (!$name) {
  46     Irssi::print("Unknown country code: $country");
  47   } else {
  48     Irssi::print("$country is $name");
  49   }
  50 }
  51 
  52 Irssi::command_bind('country', \&cmd_country);
  53 Irssi::signal_add_first('event 311', \&sig_whois);
  54 Irssi::expando_create('whois_country', \&expando_whois_country, 
  55 		      { 'event 311' => 'None' } );
  56 
  57 my $countryfile = '
  58 # list taken from http://www.iana.org/cctld/cctld-whois.htm
  59 # on 27-10-2002 by Lam
  60 ac	Ascension Island
  61 ad	Andorra
  62 ae	United Arab Emirates
  63 af	Afghanistan
  64 ag	Antigua and Barbuda
  65 ai	Anguilla
  66 al	Albania
  67 am	Armenia
  68 an	Netherlands Antilles
  69 ao	Angola
  70 aq	Antarctica
  71 ar	Argentina
  72 as	American Samoa
  73 at	Austria
  74 au	Australia
  75 aw	Aruba
  76 az	Azerbaijan
  77 ba	Bosnia and Herzegovina
  78 bb	Barbados
  79 bd	Bangladesh
  80 be	Belgium
  81 bf	Burkina Faso
  82 bg	Bulgaria
  83 bh	Bahrain
  84 bi	Burundi
  85 bj	Benin
  86 bm	Bermuda
  87 bn	Brunei Darussalam
  88 bo	Bolivia
  89 br	Brazil
  90 bs	Bahamas
  91 bt	Bhutan
  92 bv	Bouvet Island
  93 bw	Botswana
  94 by	Belarus
  95 bz	Belize
  96 ca	Canada
  97 cc	Cocos (Keeling) Islands
  98 cd	Congo	Democratic Republic of the
  99 cf	Central African Republic
 100 cg	Congo	Republic of
 101 ch	Switzerland
 102 ci	Cote d\\\'Ivoire
 103 ck	Cook Islands
 104 cl	Chile
 105 cm	Cameroon
 106 cn	China
 107 co	Colombia
 108 cr	Costa Rica
 109 cu	Cuba
 110 cv	Cap Verde
 111 cx	Christmas Island
 112 cy	Cyprus
 113 cz	Czech Republic
 114 de	Germany
 115 dj	Djibouti
 116 dk	Denmark
 117 dm	Dominica
 118 do	Dominican Republic
 119 dz	Algeria
 120 ec	Ecuador
 121 ee	Estonia
 122 eg	Egypt
 123 eh	Western Sahara
 124 er	Eritrea
 125 es	Spain
 126 et	Ethiopia
 127 fi	Finland
 128 fj	Fiji
 129 fk	Falkland Islands (Malvina)
 130 fm	Micronesia	Federal State of
 131 fo	Faroe Islands
 132 fr	France
 133 ga	Gabon
 134 gd	Grenada
 135 ge	Georgia
 136 gf	French Guiana
 137 gg	Guernsey
 138 gh	Ghana
 139 gi	Gibraltar
 140 gl	Greenland
 141 gm	Gambia
 142 gn	Guinea
 143 gp	Guadeloupe
 144 gq	Equatorial Guinea
 145 gr	Greece
 146 gs	South Georgia and the South Sandwich Islands
 147 gt	Guatemala
 148 gu	Guam
 149 gw	Guinea-Bissau
 150 gy	Guyana
 151 hk	Hong Kong
 152 hm	Heard and McDonald Islands
 153 hn	Honduras
 154 hr	Croatia/Hrvatska
 155 ht	Haiti
 156 hu	Hungary
 157 id	Indonesia
 158 ie	Ireland
 159 il	Israel
 160 im	Isle of Man
 161 in	India
 162 io	British Indian Ocean Territory
 163 iq	Iraq
 164 ir	Iran (Islamic Republic of)
 165 is	Iceland
 166 it	Italy
 167 je	Jersey
 168 jm	Jamaica
 169 jo	Jordan
 170 jp	Japan
 171 ke	Kenya
 172 kg	Kyrgyzstan
 173 kh	Cambodia
 174 ki	Kiribati
 175 km	Comoros
 176 kn	Saint Kitts and Nevis
 177 kp	Korea	Democratic People\\\'s Republic
 178 kr	Korea	Republic of
 179 kw	Kuwait
 180 ky	Cayman Islands
 181 kz	Kazakhstan
 182 la	Lao People\\\'s Democratic Republic
 183 lb	Lebanon
 184 lc	Saint Lucia
 185 li	Liechtenstein
 186 lk	Sri Lanka
 187 lr	Liberia
 188 ls	Lesotho
 189 lt	Lithuania
 190 lu	Luxembourg
 191 lv	Latvia
 192 ly	Libyan Arab Jamahiriya
 193 ma	Morocco
 194 mc	Monaco
 195 md	Moldova	Republic of
 196 mg	Madagascar
 197 mh	Marshall Islands
 198 mk	Macedonia	Former Yugoslav Republic
 199 ml	Mali
 200 mm	Myanmar
 201 mn	Mongolia
 202 mo	Macau
 203 mp	Northern Mariana Islands
 204 mq	Martinique
 205 mr	Mauritania
 206 ms	Montserrat
 207 mt	Malta
 208 mu	Mauritius
 209 mv	Maldives
 210 mw	Malawi
 211 mx	Mexico
 212 my	Malaysia
 213 mz	Mozambique
 214 na	Namibia
 215 nc	New Caledonia
 216 ne	Niger
 217 nf	Norfolk Island
 218 ng	Nigeria
 219 ni	Nicaragua
 220 nl	Netherlands
 221 no	Norway
 222 np	Nepal
 223 nr	Nauru
 224 nu	Niue
 225 nz	New Zealand
 226 om	Oman
 227 pa	Panama
 228 pe	Peru
 229 pf	French Polynesia
 230 pg	Papua New Guinea
 231 ph	Philippines
 232 pk	Pakistan
 233 pl	Poland
 234 pm	St. Pierre and Miquelon
 235 pn	Pitcairn Island
 236 pr	Puerto Rico
 237 ps	Palestinian Territories
 238 pt	Portugal
 239 pw	Palau
 240 py	Paraguay
 241 qa	Qatar
 242 re	Reunion Island
 243 ro	Romania
 244 ru	Russian Federation
 245 rw	Rwanda
 246 sa	Saudi Arabia
 247 sb	Solomon Islands
 248 sc	Seychelles
 249 sd	Sudan
 250 se	Sweden
 251 sg	Singapore
 252 sh	St. Helena
 253 si	Slovenia
 254 sj	Svalbard and Jan Mayen Islands
 255 sk	Slovak Republic
 256 sl	Sierra Leone
 257 sm	San Marino
 258 sn	Senegal
 259 so	Somalia
 260 sr	Suriname
 261 st	Sao Tome and Principe
 262 sv	El Salvador
 263 sy	Syrian Arab Republic
 264 sz	Swaziland
 265 tc	Turks and Caicos Islands
 266 td	Chad
 267 tf	French Southern Territories
 268 tg	Togo
 269 th	Thailand
 270 tj	Tajikistan
 271 tk	Tokelau
 272 tm	Turkmenistan
 273 tn	Tunisia
 274 to	Tonga
 275 tp	East Timor
 276 tr	Turkey
 277 tt	Trinidad and Tobago
 278 tv	Tuvalu
 279 tw	Taiwan
 280 tz	Tanzania
 281 ua	Ukraine
 282 ug	Uganda
 283 uk	United Kingdom
 284 um	US Minor Outlying Islands
 285 us	United States
 286 uy	Uruguay
 287 uz	Uzbekistan
 288 va	Holy See (City Vatican State)
 289 vc	Saint Vincent and the Grenadines
 290 ve	Venezuela
 291 vg	Virgin Islands (British)
 292 vi	Virgin Islands (USA)
 293 vn	Vietnam
 294 vu	Vanuatu
 295 wf	Wallis and Futuna Islands
 296 ws	Western Samoa
 297 ye	Yemen
 298 yt	Mayotte
 299 yu	Yugoslavia
 300 za	South Africa
 301 zm	Zambia
 302 zw	Zimbabwe
 303 # these are my own inventions
 304 com	commercial
 305 net	network
 306 org	organisation
 307 edu	educational
 308 mil	military
 309 gov	government
 310 aero	air-transport
 311 biz	business
 312 coop	cooperative
 313 info	informative
 314 museum	museum
 315 name	individual
 316 pro	profession
 317 ';
 318 
 319 foreach my $line (split(/\n/, $countryfile)) {
 320   chomp $line;
 321   next if ($line =~ /^#/ || $line eq ""); 
 322 
 323   my ($code, $name) = split(/\t/, $line);
 324   $countries{$code} = $name;
 325 }