| |
| /pliant/protocol/whois/client.pli |
| |
| 1 |
abstract | |
| 2 |
[This is a service derived from WHOIS client (WHOIS service is defined in RFC 954).] ; eol | |
| 3 |
| |
| 4 |
module "/pliant/language/stream.pli" | |
| 5 |
| |
| 6 |
constant whois_server "whois.ripe.net" # "193.0.0.200" | |
| 7 |
constant whois_options "-F -r -T inetnum " | |
| 8 |
constant whois_append "/32" | |
| 9 |
constant trace false | |
| 10 |
| |
| 11 |
function whois_ip_country ip -> country | |
| 12 |
arg Str ip country | |
| 13 |
var Str cmd := whois_options+ip+whois_append | |
| 14 |
country := "" | |
| 15 |
(var Stream s) open "tcp://"+whois_server+"/client/43" in+out+cr+lf+safe | |
| 16 |
s writeline cmd | |
| 17 |
if trace | |
| 18 |
console "? " cmd eol | |
| 19 |
while not s:atend | |
| 20 |
var Str l := s readline | |
| 21 |
if trace | |
| 22 |
console l eol | |
| 23 |
if (lower:l parse "country" ":" any:(var Str c)) or (lower:l parse "*" "cy" ":" any:(var Str c)) | |
| 24 |
country := c | |
| 25 |
| |
| 26 |
export whois_ip_country | |
| |