File: iptab

package info (click to toggle)
libnet-ip-perl 1.26-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 464 kB
  • ctags: 280
  • sloc: perl: 1,321; makefile: 17
file content (58 lines) | stat: -rwxr-xr-x 888 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!perl

use Net::IP;
use strict;

print "+----------------------------------------------+
| addrs   bits   pref   class  mask            |
+----------------------------------------------+
";

my ($ip,$size,$class,$bits,$len);

my $ip = new Net::IP('0');

for my $len (reverse (0..32))
{

	$ip->set("0.0.0.0/$len");

	$size = $ip->size();
	
	if ($size >=1048576) # 1024*1024
	{
		$size /= 1048576;
		$size .= 'M';
	}
	elsif ($size >= 1024)
	{
		$size /= 1024;
		$size .= 'K';
	};		
	
	$len = $ip->prefixlen();
	$bits = 32 - $len;
	
	if ($bits >= 24)
	{
		$class = 2**($bits-24);
		$class.= 'A';
	}
	elsif ($bits >= 16)
	{
		$class = 2**($bits-16);
		$class.= 'B';
	}	
	elsif ($bits >= 8)
	{
		$class = 2**($bits-8);
		$class.= 'C';
	}	

	printf ("| %5s %6s %6s %7s  %-15s |\n",
		$size,$bits,'/'.$len,$class,$ip->mask());
	

};

print "+----------------------------------------------+\n";