perl - How do I sort a list of IP addresses and compute a class and netmask for each? -
i have 2 options. 1 have array has list of ips. example
@ip=(); # array has ips below in
sample input:
108.0.0.30 108.0.0.30 108.0.0.30 192.168.1.1 192.168.1.2 10.0.0.1
i need program can sort such array , tell network class , subnet mask is. example, output should
10.1.1.1/25 10.1.1.1 ip , 25 submask
net::ip
, net::ip::resolver
, net::ip::match::regexp
, other submodules net::ip
doing fine you. part sorting difficult. if google it, find nice methods. example:
my @ips = qw( 172.27.32.200 172.19.32.100 10.1.1.60 192.20.30.133 ); @ips = map {s/\s+//g; $_} sort map {s/(\d+)/sprintf "%3s", $1/eg; $_} @ips; print join "\n", @ips;
Comments
Post a Comment