{"id":79,"date":"2007-02-24T20:56:10","date_gmt":"2007-02-25T01:56:10","guid":{"rendered":"http:\/\/raffy.ch\/blog\/2007\/02\/24\/geo-lookup-on-the-command-line\/"},"modified":"2007-02-24T20:57:32","modified_gmt":"2007-02-25T01:57:32","slug":"geo-lookup-on-the-command-line","status":"publish","type":"post","link":"https:\/\/raffy.ch\/blog\/2007\/02\/24\/geo-lookup-on-the-command-line\/","title":{"rendered":"Geo Lookup on the Command Line"},"content":{"rendered":"<p>By now you should know that I really like command line tools which operate well when applied to data through a pipe. I have posted quite a few tips already to do data manipulation on the command line. Today I wanted a quick way to lookup IP address locations and add them to a log file. After investigating a few free databases, I came accross <strong>Geo::IPFree<\/strong>, a Perl library which does the trick. So here is how you add the country code. First, this is the format of my log entries:<\/p>\n<p><code>10\/13\/2005 20:25:54.032145,195.141.211.178,195.131.61.44,2071,135<\/code><\/p>\n<p>I want to get the country of the source address (first IP in the log). Here we go:<\/p>\n<p><code> cat pflog.csv | perl -M'Geo::IPfree' -na -F\/,\/ -e '($country,$country_name)=Geo::IPfree::LookUp($F[1]);chomp; print \"$_,$country_name\\n\"'<\/code><\/p>\n<p>And here the output:<\/p>\n<p><code>10\/13\/2005 20:24:33.494358,62.245.243.139,212.254.111.99,,echo request,Europe<\/code><\/p>\n<p>Very simple!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By now you should know that I really like command line tools which operate well when applied to data through a pipe. I have posted quite a few tips already to do data manipulation on the command line. Today I wanted a quick way to lookup IP address locations and add them to a log [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-programming","category-unix-scripting"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/raffy.ch\/blog\/wp-json\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raffy.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raffy.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raffy.ch\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raffy.ch\/blog\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":0,"href":"https:\/\/raffy.ch\/blog\/wp-json\/wp\/v2\/posts\/79\/revisions"}],"wp:attachment":[{"href":"https:\/\/raffy.ch\/blog\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raffy.ch\/blog\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raffy.ch\/blog\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}