我需要脚本与相应的用户名和电子邮件地址以及国家/地区逐行打印出 IP 地址列表。如何获取多个 IP 地址来执行命令?我试着做一个循环,但它只显示了一行 IP 地址。我希望我的输出看起来像:
1 | login | emailadd@yahoo.com | 160.79.208.82 | United States
16 | login1 | emailadd@yahoo.com | 61.95.83.10 | Italy
23 | login2 | emailadd@gmail.com | 81.48.63.93 | Australia
36 | login3 | emailadd@yahoo.com | 38.117.170.82 | Japan
51 | login4 | emailadd@gmail.com | 2.233.30.85 | Mexico
这是我的代码:
#!/usr/bin/perl -w
use lib '~/lib';
use strict;
use Net::IPInfoDB;
my $g = Net::IPInfoDB->new;
$g->key(api_key);
my $login = '1 | login | emailadd@yahoo.com | 160.79.208.82
16 | login1 | emailadd@yahoo.com | 61.95.83.10
23 | login2 | emailadd@gmail.com | 81.48.63.93
36 | login3 | emailadd@yahoo.com | 38.117.170.82
51 | login4 | emailadd@gmail.com | 2.233.30.85';
$login =~ /(\d+\.\d+\.\d+\.\d+)/;
my $city = $g->get_city("$1");
my $addr = $g->get_country("$1");
printf "$login | (%s, %s)\n",
$city->city_name, $addr->country_name;