Знает ли кто-нибудь более-менее универсальный способ вытаскивания кода страны из выхлопа whois, с учётом всего возможного разнообразия этих выхлопов? Т.е. мне требуется, чтобы на выходе всегда был двухбуквенный код страны.
Пока пользуюсь вот такой конструкцией, но она довольно неряшлива:
а какая разница? парсить всё равно придётся. И код будет такой-же по сложности и длине. Или я чего-то не знаю?
Во-первых вывод не меняющейся без вашего ведома утилиты всегда выглядит одинаково, а удалённые whois-сервера могут быть кто-их-знает какими, и выдавать ответы в непредсказуемом формате и с различным составом и названиями полей.
Во-вторых выборка информации из локально лежащей БД стран/подсетей выполняется мгновенно, в отличие от whois'а, лезти за которым нужно порой за тридевять земель.
$ for i in me ru us co.uk de com net ae li ; do
echo -e "\ngoogle.$i" ;
whois google.$i | grep -i country ; done
google.me
Trademark Country:BX
Registrant Country/Economy:US
Admin Country/Economy:US
Tech Country/Economy:US
google.ru
google.us
Registrant Country: United States
Registrant Country Code: US
Administrative Contact Country: United States
Administrative Contact Country Code: US
Billing Contact Country: United States
Billing Contact Country Code: US
Technical Contact Country: United States
Technical Contact Country Code: US
google.co.uk
google.de
CountryCode: US
CountryCode: US
google.com
google.net
google.ae
google.li
$ for i in me ru us co.uk de com net ae li ; do echo -e "\ngoogle.$i" ; geoiplookup google.$i ; done
google.me
GeoIP Country Edition: US, United States
google.ru
GeoIP Country Edition: US, United States
google.us
GeoIP Country Edition: US, United States
google.co.uk
GeoIP Country Edition: US, United States
google.de
GeoIP Country Edition: US, United States
google.com
GeoIP Country Edition: US, United States
google.net
GeoIP Country Edition: US, United States
google.ae
GeoIP Country Edition: US, United States
google.li
GeoIP Country Edition: US, United States
$ for i in me ru us co.uk de com net ae li ; do echo -e "\n$(host google.$i|sed 's/.*ess //;q')" ; geoiplookup $(host google.$i|sed 's/.*ess //;q') ; done
74.125.232.49
GeoIP Country Edition: US, United States
74.125.232.55
GeoIP Country Edition: US, United States
74.125.232.52
GeoIP Country Edition: US, United States
74.125.232.63
GeoIP Country Edition: US, United States
74.125.232.56
GeoIP Country Edition: US, United States
173.194.47.142
GeoIP Country Edition: US, United States
74.125.232.50
GeoIP Country Edition: US, United States
74.125.232.56
GeoIP Country Edition: US, United States
74.125.232.55
GeoIP Country Edition: US, United States
$ for i in me ru us co.uk de com net ae li ; do echo -e "\n$(host google.$i|sed 's/.*ess //;q')" ; whois $(host google.$i|sed 's/.*ess //;q') | grep -i country ; done
74.125.232.50
Country: US
74.125.232.63
Country: US
74.125.232.52
Country: US
74.125.232.63
Country: US
74.125.232.55
Country: US
173.194.47.169
Country: US
74.125.232.48
Country: US
74.125.232.55
Country: US
74.125.232.63
Country: US