@@ -11,6 +11,9 @@ =head1 list-shared-addresses.pl
11
11
and easily parsed list with the C<--multiline > flag. Or to just get a list
12
12
of addresses, use the C<--name-only > parameter.
13
13
14
+ By default only shared IPv4 addresses are shown, but you can use the C<--ipv6 >
15
+ flag to also include IPv6 addresses.
16
+
14
17
=cut
15
18
16
19
package virtual_server ;
@@ -32,24 +35,59 @@ package virtual_server;
32
35
# Parse command-line args
33
36
$owner = 1;
34
37
&parse_common_cli_flags(\@ARGV );
38
+ $ipv4 = 1;
39
+ $ipv6 = 0;
35
40
while (@ARGV > 0) {
36
41
local $a = shift (@ARGV );
37
- &usage(" Unknown parameter $a " );
42
+ if ($a eq " --ipv6" ) {
43
+ $ipv6 = 1;
44
+ }
45
+ elsif ($a eq " --no-ipv6" ) {
46
+ $ipv6 = 0;
47
+ }
48
+ elsif ($a eq " --ipv4" ) {
49
+ $ipv4 = 1;
50
+ }
51
+ elsif ($a eq " --no-ipv4" ) {
52
+ $ipv4 = 0;
53
+ }
54
+ else {
55
+ &usage(" Unknown parameter $a " );
56
+ }
38
57
}
58
+ $ipv4 || $ipv6 || &usage(" At least one of IPv4 or IPv6 mode must be enabled" );
59
+ !$ipv6 || &supports_ip6() || &usage(" This system does not support IPv6" );
39
60
40
61
# Get the IPs
41
- push (@ips , { ' ip' => &get_default_ip(), ' type' => ' default' });
62
+ if ($ipv4 ) {
63
+ push (@ips , { ' ip' => &get_default_ip(), ' type' => ' default' });
64
+ }
65
+ if ($ipv4 ) {
66
+ push (@ips , { ' ip' => &get_default_ip6(), ' type' => ' default' });
67
+ }
42
68
if (defined (&list_resellers)) {
43
69
foreach $r (&list_resellers()) {
44
- if ($r -> {' acl' }-> {' defip' }) {
70
+ if ($ipv4 && $ r-> {' acl' }-> {' defip' }) {
45
71
push (@ips , { ' ip' => $r -> {' acl' }-> {' defip' },
46
72
' type' => ' reseller' ,
47
73
' reseller' => $r -> {' name' } });
48
74
}
75
+ if ($ipv6 && $r -> {' acl' }-> {' defip6' }) {
76
+ push (@ips , { ' ip' => $r -> {' acl' }-> {' defip6' },
77
+ ' type' => ' reseller' ,
78
+ ' reseller' => $r -> {' name' } });
79
+ }
49
80
}
50
81
}
51
- foreach $ip (&list_shared_ips()) {
52
- push (@ips , { ' ip' => $ip , ' type' => ' shared' });
82
+ if ($ipv4 ) {
83
+ foreach $ip (&list_shared_ips()) {
84
+ push (@ips , { ' ip' => $ip , ' type' => ' shared' });
85
+ }
86
+ }
87
+ if ($ipv6 ) {
88
+ foreach $ip (&list_shared_ip6s()) {
89
+ push (@ips , { ' ip' => $ip , ' type' => ' shared' });
90
+ }
53
91
}
54
92
55
93
if ($multiline ) {
@@ -60,7 +98,8 @@ package virtual_server;
60
98
if ($ip -> {' reseller' }) {
61
99
print " Reseller: $ip ->{'reseller'}\n "
62
100
}
63
- @doms = &get_domain_by(" ip" , $ip -> {' ip' });
101
+ @doms = (&get_domain_by(" ip" , $ip -> {' ip' }),
102
+ &get_domain_by(" ip6" , $ip -> {' ip' }));
64
103
foreach $d (@doms ) {
65
104
print " Virtual server: $d ->{'dom'}\n " ;
66
105
}
@@ -94,6 +133,8 @@ sub usage
94
133
print " \n " ;
95
134
print " virtualmin list-shared-addresses [--multiline | --json | --xml |\n " ;
96
135
print " --name-only]\n " ;
136
+ print " [--ipv4 | --no-ipv4]\n " ;
137
+ print " [--ipv6 | --no-ipv6]\n " ;
97
138
exit (1);
98
139
}
99
140
0 commit comments