特定信息标记的http://ipinfo.io入门示例如下所示:
cat ips.txt | xargs -I% curl -s http://ipinfo.io/%/org | paste -d"," ips.txt -返回:
8.8.8.8,AS15169 Google Inc.
8.8.4.4,AS15169 Google Inc.
1.2.3.4,AS15169 Google Inc.我想要多个信息,所以我把这里的例子改为:
cat ips.txt | xargs -I% curl -s http://ipinfo.io/%/city http://ipinfo.io/%/region | paste -d"," ips.txt - > ip_info.txt返回:
156.221.17.167,Punjab
,Dol pri Ljubljani我如何格式化我的请求,以适应所有与IP相关的信息,用逗号‘分隔的同一行,如下所示:
156.221.17.167,Punjab,Dol pri Ljubljani发布于 2017-01-12 23:14:26
如果您需要多个信息片段,最好是在一个请求中获得所有信息,然后使用jq提取所需的信息片段。下面是IP的完整JSON输出(更多示例请参见http://ipinfo.io/developers ):
$ curl ipinfo.io/8.8.8.8
{
"ip": "8.8.8.8",
"hostname": "google-public-dns-a.google.com",
"city": "Mountain View",
"region": "California",
"country": "US",
"loc": "37.3860,-122.0838",
"org": "AS15169 Google Inc.",
"postal": "94035"
}然后使用jq将IP、城市和国家提取到CSV:
$ curl -s ipinfo.io/8.8.8.8 | jq -r '[.ip, .city, .country] | @csv'
"8.8.8.8","Mountain View","US"如果我们有一组it文件,我们可以这样做:
$ cat ips.txt | xargs -I% curl -s http://ipinfo.io/%/json | jq -r '[.ip, .city, .country] | @csv'https://stackoverflow.com/questions/41597393
复制相似问题