-
Notifications
You must be signed in to change notification settings - Fork 0
/
isis-net.pl
executable file
·83 lines (58 loc) · 1.67 KB
/
isis-net.pl
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl
#
# convert between is-is net and ip address
if (!$ARGV[0]) { print "usage: $0 (<ip address>|<is-is net>)\n"; exit 1; }
$foo = $ARGV[0];
# ip address
if ($foo =~ /(?<!\d)(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})(?!\d)/g)
{
if (
$1 >= 0 && $1 <= 255 &&
$2 >= 0 && $2 <= 255 &&
$3 >= 0 && $3 <= 255 &&
$4 >= 0 && $4 <= 255
) {
# need to pad each octet with left 0's
$o1 = sprintf "%03d", $1;
$o2 = sprintf "%03d", $2;
$o3 = sprintf "%03d", $3;
$o4 = sprintf "%03d", $4;
# need to concat all octets
$concat = $o1.$o2.$o3.$o4;
# need to cut by groups of 4, print out with "." between (done)
@segments = unpack ('A4 A4 A4', $concat);
$isisformat = $segments[0].".".$segments[1].".".$segments[2];
print "$isisformat\n";
exit 0;
}
}
# is-is net
# Only supporting formats of: 49.0001.1720.1600.1001.00 or 1720.1600.1001
# 49.0001.1720.1600.1001.00
if ($foo =~ /^[0-9]{2}\.([0-9]{4}\.){4}[0-9]{2}$/)
{
@segments = split(/\./, $foo);
$concat = $segments[2].$segments[3].$segments[4];
@octets = unpack ('A3 A3 A3 A3', $concat);
$octets[0] =~ s/^\s*0+//;
$octets[1] =~ s/^\s*0+//;
$octets[2] =~ s/^\s*0+//;
$octets[3] =~ s/^\s*0+//;
print "$octets[0]\.$octets[1]\.$octets[2]\.$octets[3]\n";
exit 0;
}
# 1720.1600.1001
if ($foo =~ /^([0-9]{4}\.){2}[0-9]{4}$/)
{
@segments = split(/\./, $foo);
$concat = $segments[0].$segments[1].$segments[2];
@octets = unpack ('A3 A3 A3 A3', $concat);
$octets[0] =~ s/^\s*0+//;
$octets[1] =~ s/^\s*0+//;
$octets[2] =~ s/^\s*0+//;
$octets[3] =~ s/^\s*0+//;
print "$octets[0]\.$octets[1]\.$octets[2]\.$octets[3]\n";
exit 0;
}
print "Bad format.\n";
exit 1;