一个判断ipv4或ipv6的perl程序:
more 1.pl
#!/usr/bin/perl
use Net::IP::Checker qw[:ALL];
my $ip = ‘172.16.0.216’;
ip_is_ipv4( $ip ) and print “$ip is IPv4\n”;
$ip = ‘dead:beef:89ab:cdef:0123:4567:89ab:cdef’;
ip_is_ipv6( $ip ) and print “$ip is IPv6\n”;
print ip_get_version( $ip );
直接执行会报错,没有相关模块。
要先安装cpanm 这个利器:
yum install perl-App-cpanminus.noarch
安装所需模块:
cpanm Net/IP/Checker.pm
再次执行:
[root@centos7 perl]# perl 1.pl
172.16.0.216 is IPv4
dead:beef:89ab:cdef:0123:4567:89ab:cdef is IPv6