| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Hardware::Network::Solaris; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
14
|
use v5.12.5; |
|
|
1
|
|
|
|
|
11
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
52
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
12
|
use Rex::Logger; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
7
|
|
|
13
|
1
|
|
|
1
|
|
40
|
use Rex::Helper::Run; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
75
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use Rex::Helper::Array; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1592
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub get_network_devices { |
|
17
|
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
0
|
|
my @device_list = map { /^([a-z0-9]+)\:/i } i_run "ifconfig -a"; |
|
|
0
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
@device_list = array_uniq(@device_list); |
|
21
|
0
|
|
|
|
|
|
return \@device_list; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get_network_configuration { |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
0
|
|
my $devices = get_network_devices(); |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $device_info = {}; |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
for my $dev ( @{$devices} ) { |
|
|
0
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $ifconfig = i_run("ifconfig $dev"); |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$device_info->{$dev} = { |
|
36
|
|
|
|
|
|
|
ip => [ ( $ifconfig =~ m/inet (\d+\.\d+\.\d+\.\d+)/ ) ]->[0], |
|
37
|
|
|
|
|
|
|
netmask => [ ( $ifconfig =~ m/(netmask 0x|netmask )([a-f0-9]+)/ ) ]->[1], |
|
38
|
|
|
|
|
|
|
broadcast => [ ( $ifconfig =~ m/broadcast (\d+\.\d+\.\d+\.\d+)/ ) ]->[0], |
|
39
|
|
|
|
|
|
|
mac => [ |
|
40
|
|
|
|
|
|
|
( $ifconfig =~ m/(ether|address:|lladdr) (..?:..?:..?:..?:..?:..?)/ ) |
|
41
|
|
|
|
|
|
|
]->[1], |
|
42
|
|
|
|
|
|
|
is_bridge => 0, |
|
43
|
|
|
|
|
|
|
}; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return $device_info; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub route { |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
0
|
0
|
|
my @ret = (); |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my @route = i_run "netstat -nr", fail_ok => 1; |
|
56
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
57
|
0
|
|
|
|
|
|
die("Error running netstat"); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
shift @route; |
|
61
|
0
|
|
|
|
|
|
shift @route; # remove first 2 lines |
|
62
|
0
|
|
|
|
|
|
shift @route; |
|
63
|
0
|
|
|
|
|
|
shift @route; # remove first 2 lines |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
for my $route_entry (@route) { |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
0
|
0
|
|
|
|
if ( $route_entry =~ m/^$/ |
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|| $route_entry =~ m/^Routing Table:/ |
|
69
|
|
|
|
|
|
|
|| $route_entry =~ m/^\s+Destination/ |
|
70
|
|
|
|
|
|
|
|| $route_entry =~ m/^---------/ ) |
|
71
|
|
|
|
|
|
|
{ |
|
72
|
0
|
|
|
|
|
|
next; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my ( $dest, $gw, $flags, $ref, $use, $iface ) = |
|
76
|
|
|
|
|
|
|
split( /\s+/, $route_entry, 6 ); |
|
77
|
0
|
|
|
|
|
|
push( |
|
78
|
|
|
|
|
|
|
@ret, |
|
79
|
|
|
|
|
|
|
{ |
|
80
|
|
|
|
|
|
|
destination => $dest, |
|
81
|
|
|
|
|
|
|
gateway => $gw, |
|
82
|
|
|
|
|
|
|
flags => $flags, |
|
83
|
|
|
|
|
|
|
ref => $ref, |
|
84
|
|
|
|
|
|
|
use => $use, |
|
85
|
|
|
|
|
|
|
iface => $iface, |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return @ret; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub default_gateway { |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
0
|
0
|
|
my ( $class, $new_default_gw ) = @_; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
if ($new_default_gw) { |
|
99
|
0
|
0
|
|
|
|
|
if ( default_gateway() ) { |
|
100
|
0
|
|
|
|
|
|
i_run "route delete default " . default_gateway(), fail_ok => 1; |
|
101
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
102
|
0
|
|
|
|
|
|
die("Error running route del default"); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
i_run "route add default $new_default_gw", fail_ok => 1; |
|
107
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
108
|
0
|
|
|
|
|
|
die("Error route add default"); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
else { |
|
113
|
0
|
|
|
|
|
|
my @route = route(); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my ($default_route) = grep { |
|
116
|
0
|
|
|
|
|
|
$_->{"flags"} =~ m/UG/ |
|
117
|
|
|
|
|
|
|
&& ( $_->{"destination"} eq "0.0.0.0" |
|
118
|
0
|
0
|
0
|
|
|
|
|| $_->{"destination"} eq "default" ) |
|
119
|
|
|
|
|
|
|
} @route; |
|
120
|
0
|
0
|
|
|
|
|
return $default_route->{"gateway"} if $default_route; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub netstat { |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
0
|
0
|
|
my @ret; |
|
127
|
0
|
|
|
|
|
|
my @netstat = i_run "netstat -na -f inet -f inet6", fail_ok => 1; |
|
128
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
129
|
0
|
|
|
|
|
|
die("Error running netstat"); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my ( $proto, $udp_v4, $udp_v6, $tcp_v4, $tcp_v6, $sctp ); |
|
133
|
0
|
|
|
|
|
|
for my $line (@netstat) { |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
0
|
0
|
|
|
|
if ( $line =~ m/^$/ |
|
|
|
|
0
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|| $line =~ m/^\s+Local/ |
|
137
|
|
|
|
|
|
|
|| $line =~ m/^--------/ ) |
|
138
|
|
|
|
|
|
|
{ |
|
139
|
0
|
|
|
|
|
|
next; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
if ( $line =~ m/^UDP: IPv4/ ) { |
|
143
|
0
|
|
|
|
|
|
$udp_v4 = 0; |
|
144
|
0
|
|
|
|
|
|
$udp_v6 = 0; |
|
145
|
0
|
|
|
|
|
|
$tcp_v4 = 0; |
|
146
|
0
|
|
|
|
|
|
$tcp_v6 = 0; |
|
147
|
0
|
|
|
|
|
|
$sctp = 0; |
|
148
|
0
|
|
|
|
|
|
$udp_v4 = 1; |
|
149
|
0
|
|
|
|
|
|
$proto = "udp"; |
|
150
|
0
|
|
|
|
|
|
next; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
0
|
0
|
|
|
|
|
if ( $line =~ m/^UDP: IPv6/ ) { |
|
154
|
0
|
|
|
|
|
|
$udp_v4 = 0; |
|
155
|
0
|
|
|
|
|
|
$udp_v6 = 0; |
|
156
|
0
|
|
|
|
|
|
$tcp_v4 = 0; |
|
157
|
0
|
|
|
|
|
|
$tcp_v6 = 0; |
|
158
|
0
|
|
|
|
|
|
$sctp = 0; |
|
159
|
0
|
|
|
|
|
|
$udp_v6 = 1; |
|
160
|
0
|
|
|
|
|
|
$proto = "udp6"; |
|
161
|
0
|
|
|
|
|
|
next; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
0
|
0
|
|
|
|
|
if ( $line =~ m/^TCP: IPv4/ ) { |
|
165
|
0
|
|
|
|
|
|
$udp_v4 = 0; |
|
166
|
0
|
|
|
|
|
|
$udp_v6 = 0; |
|
167
|
0
|
|
|
|
|
|
$tcp_v4 = 0; |
|
168
|
0
|
|
|
|
|
|
$tcp_v6 = 0; |
|
169
|
0
|
|
|
|
|
|
$sctp = 0; |
|
170
|
0
|
|
|
|
|
|
$tcp_v4 = 1; |
|
171
|
0
|
|
|
|
|
|
$proto = "tcp"; |
|
172
|
0
|
|
|
|
|
|
next; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
0
|
0
|
|
|
|
|
if ( $line =~ m/^TCP: IPv6/ ) { |
|
176
|
0
|
|
|
|
|
|
$udp_v4 = 0; |
|
177
|
0
|
|
|
|
|
|
$udp_v6 = 0; |
|
178
|
0
|
|
|
|
|
|
$tcp_v4 = 0; |
|
179
|
0
|
|
|
|
|
|
$tcp_v6 = 0; |
|
180
|
0
|
|
|
|
|
|
$sctp = 0; |
|
181
|
0
|
|
|
|
|
|
$tcp_v6 = 1; |
|
182
|
0
|
|
|
|
|
|
$proto = "tcp6"; |
|
183
|
0
|
|
|
|
|
|
next; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
0
|
0
|
|
|
|
|
if ( $line =~ m/^SCTP:/ ) { |
|
187
|
0
|
|
|
|
|
|
$udp_v4 = 0; |
|
188
|
0
|
|
|
|
|
|
$udp_v6 = 0; |
|
189
|
0
|
|
|
|
|
|
$tcp_v4 = 0; |
|
190
|
0
|
|
|
|
|
|
$tcp_v6 = 0; |
|
191
|
0
|
|
|
|
|
|
$sctp = 0; |
|
192
|
0
|
|
|
|
|
|
$sctp = 1; |
|
193
|
0
|
|
|
|
|
|
$proto = "sctp"; |
|
194
|
0
|
|
|
|
|
|
next; |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
$line =~ s/^\s+//; |
|
198
|
|
|
|
|
|
|
|
|
199
|
0
|
0
|
|
|
|
|
if ($udp_v4) { |
|
200
|
0
|
|
|
|
|
|
$line = " $line"; |
|
201
|
0
|
|
|
|
|
|
my ( $local_addr, $remote_addr, $state ) = |
|
202
|
|
|
|
|
|
|
( $line =~ m/\s+?([^\s]+)\s+([^\s]+)?\s+([^\s]+)/ ); |
|
203
|
0
|
|
|
|
|
|
push( |
|
204
|
|
|
|
|
|
|
@ret, |
|
205
|
|
|
|
|
|
|
{ |
|
206
|
|
|
|
|
|
|
proto => $proto, |
|
207
|
|
|
|
|
|
|
local_addr => $local_addr, |
|
208
|
|
|
|
|
|
|
foreign_addr => $remote_addr, |
|
209
|
|
|
|
|
|
|
state => $state, |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
); |
|
212
|
0
|
|
|
|
|
|
next; |
|
213
|
|
|
|
|
|
|
} |
|
214
|
|
|
|
|
|
|
|
|
215
|
0
|
0
|
|
|
|
|
if ($udp_v6) { |
|
216
|
0
|
|
|
|
|
|
$line = " $line"; |
|
217
|
0
|
|
|
|
|
|
my ( $local_addr, $remote_addr, $state, $if ) = |
|
218
|
|
|
|
|
|
|
( $line =~ m/\s+?([^\s]+)\s+([^\s]+)?\s+([^\s]+)\s+([^\s]+)/ ); |
|
219
|
0
|
|
|
|
|
|
push( |
|
220
|
|
|
|
|
|
|
@ret, |
|
221
|
|
|
|
|
|
|
{ |
|
222
|
|
|
|
|
|
|
proto => $proto, |
|
223
|
|
|
|
|
|
|
local_addr => $local_addr, |
|
224
|
|
|
|
|
|
|
foreign_addr => $remote_addr, |
|
225
|
|
|
|
|
|
|
state => $state, |
|
226
|
|
|
|
|
|
|
if => $if, |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
); |
|
229
|
0
|
|
|
|
|
|
next; |
|
230
|
|
|
|
|
|
|
} |
|
231
|
|
|
|
|
|
|
|
|
232
|
0
|
0
|
|
|
|
|
if ($tcp_v4) { |
|
233
|
0
|
|
|
|
|
|
my ( $local_addr, $remote_addr, $swind, $sendq, $rwind, $recvq, $state ) |
|
234
|
|
|
|
|
|
|
= split( /\s+/, $line, 7 ); |
|
235
|
0
|
|
|
|
|
|
push( |
|
236
|
|
|
|
|
|
|
@ret, |
|
237
|
|
|
|
|
|
|
{ |
|
238
|
|
|
|
|
|
|
proto => $proto, |
|
239
|
|
|
|
|
|
|
local_addr => $local_addr, |
|
240
|
|
|
|
|
|
|
foreign_addr => $remote_addr, |
|
241
|
|
|
|
|
|
|
swind => $swind, |
|
242
|
|
|
|
|
|
|
sendq => $sendq, |
|
243
|
|
|
|
|
|
|
rwind => $rwind, |
|
244
|
|
|
|
|
|
|
recvq => $recvq, |
|
245
|
|
|
|
|
|
|
state => $state, |
|
246
|
|
|
|
|
|
|
} |
|
247
|
|
|
|
|
|
|
); |
|
248
|
0
|
|
|
|
|
|
next; |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
|
|
251
|
0
|
0
|
|
|
|
|
if ($tcp_v6) { |
|
252
|
0
|
|
|
|
|
|
my ( $local_addr, $remote_addr, $swind, $sendq, $rwind, $recvq, $state, |
|
253
|
|
|
|
|
|
|
$if ) |
|
254
|
|
|
|
|
|
|
= split( /\s+/, $line, 8 ); |
|
255
|
0
|
|
|
|
|
|
push( |
|
256
|
|
|
|
|
|
|
@ret, |
|
257
|
|
|
|
|
|
|
{ |
|
258
|
|
|
|
|
|
|
proto => $proto, |
|
259
|
|
|
|
|
|
|
local_addr => $local_addr, |
|
260
|
|
|
|
|
|
|
foreign_addr => $remote_addr, |
|
261
|
|
|
|
|
|
|
swind => $swind, |
|
262
|
|
|
|
|
|
|
sendq => $sendq, |
|
263
|
|
|
|
|
|
|
rwind => $rwind, |
|
264
|
|
|
|
|
|
|
recvq => $recvq, |
|
265
|
|
|
|
|
|
|
state => $state, |
|
266
|
|
|
|
|
|
|
if => $if, |
|
267
|
|
|
|
|
|
|
} |
|
268
|
|
|
|
|
|
|
); |
|
269
|
0
|
|
|
|
|
|
next; |
|
270
|
|
|
|
|
|
|
} |
|
271
|
|
|
|
|
|
|
|
|
272
|
0
|
0
|
|
|
|
|
if ($sctp) { |
|
273
|
0
|
|
|
|
|
|
my ( $local_addr, $remote_addr, $swind, $sendq, $rwind, $recvq, $strs, |
|
274
|
|
|
|
|
|
|
$state ) |
|
275
|
|
|
|
|
|
|
= split( /\s+/, $line, 8 ); |
|
276
|
0
|
|
|
|
|
|
push( |
|
277
|
|
|
|
|
|
|
@ret, |
|
278
|
|
|
|
|
|
|
{ |
|
279
|
|
|
|
|
|
|
proto => $proto, |
|
280
|
|
|
|
|
|
|
local_addr => $local_addr, |
|
281
|
|
|
|
|
|
|
foreign_addr => $remote_addr, |
|
282
|
|
|
|
|
|
|
swind => $swind, |
|
283
|
|
|
|
|
|
|
sendq => $sendq, |
|
284
|
|
|
|
|
|
|
rwind => $rwind, |
|
285
|
|
|
|
|
|
|
recvq => $recvq, |
|
286
|
|
|
|
|
|
|
state => $state, |
|
287
|
|
|
|
|
|
|
strsio => $strs, |
|
288
|
|
|
|
|
|
|
} |
|
289
|
|
|
|
|
|
|
); |
|
290
|
0
|
|
|
|
|
|
next; |
|
291
|
|
|
|
|
|
|
} |
|
292
|
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
|
|
295
|
0
|
|
|
|
|
|
@netstat = i_run "netstat -na -f unix", fail_ok => 1; |
|
296
|
0
|
|
|
|
|
|
shift @netstat; |
|
297
|
0
|
|
|
|
|
|
shift @netstat; |
|
298
|
0
|
|
|
|
|
|
shift @netstat; |
|
299
|
|
|
|
|
|
|
|
|
300
|
0
|
|
|
|
|
|
for my $line (@netstat) { |
|
301
|
0
|
|
|
|
|
|
my ( $address, $type, $vnode, $conn, $local_addr, $remote_addr ) = |
|
302
|
|
|
|
|
|
|
split( /\s+/, $line, 7 ); |
|
303
|
|
|
|
|
|
|
|
|
304
|
0
|
|
|
|
|
|
my $data = { |
|
305
|
|
|
|
|
|
|
proto => "unix", |
|
306
|
|
|
|
|
|
|
address => $address, |
|
307
|
|
|
|
|
|
|
type => $type, |
|
308
|
|
|
|
|
|
|
nvnode => $vnode, |
|
309
|
|
|
|
|
|
|
conn => $conn, |
|
310
|
|
|
|
|
|
|
path => $local_addr, |
|
311
|
|
|
|
|
|
|
}; |
|
312
|
|
|
|
|
|
|
|
|
313
|
0
|
|
|
|
|
|
push( @ret, $data ); |
|
314
|
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
} |
|
316
|
|
|
|
|
|
|
|
|
317
|
0
|
|
|
|
|
|
return @ret; |
|
318
|
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
} |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
1; |