0

I use MaxMind API to get IP Address data. What I am looking for is the country and the ASN. The MaxMind API works as follow: curl -s http://geoip.maxmind.com/e\?l\={APIKEY}\&i\={IP} And returns something like this: US,"United States",AZ,Arizona,Phoenix,33.5097,-112.0678,753,602,America/Phoenix,NA,85012,"Highwinds Network Group","Highwinds Network Group",,"AS20446 Highwinds Network Group, Inc.",Corporate,hosting,1000,99,20,60,10,%

To get the Country I use the following: loc=`curl -s http://geoip.maxmind.com/e\?l\={APIKEY}\&i\={IP} 2>&1 | awk -F',' '{print $1;}'

I want to be able to grab the ASN info. In this case that would be "AS20446 Highwinds Network Group, Inc."

How can I do that?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Laurent
  • 47

1 Answers1

0

In other words, you want to parse CSV (comma separated values) format on the Mac on the command line, paying attention to quotation (there may be commas inside the quotes, as you probably noticed...).

One popular toolkit for that is csvkit, available via Homebrew.

There are many other options to do this, e.g. using perl -e ... with the csv package.

Related questions with other options: e.g. here and here, many of these are also available on the Mac, via Homebrew or otherwise.

dirkt
  • 32,309