-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathget_network_config.sh
516 lines (371 loc) · 8.46 KB
/
get_network_config.sh
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
#!/usr/bin/ksh
#########################################################################
# ToDO : Network Configuration Output in "./ntwk.conf"
# Version : 2.0
# Author : Aleksander Pavic <[email protected]>
# OS : Sparc@Solaris 8
# Scriptname : get_network_config
# Licence : GPL
#########################################################################
function filestart
{
echo "############# Begin of Network Configuration #################" >&3
}
function separator
{
echo "" >&3
echo "##############################################################" >&3
echo "" >&3
}
function help
{
echo
echo " Network Configuration is printed to './ntwk.conf'"
echo " Format: <Attribute>=<value-in_one_line>"
echo
echo " GENERAL OPTIONS:"
echo " -c <interface_dev> - generate output for this interface"
echo " -l <instance> - interface instance between 0 - 1023 (default=0)"
echo " -V - version"
echo " -h - this screen"
echo " -p - print generated output file"
echo
echo " OUTPUT MODIFIERS:"
echo " -a - all O.M. without '-v'"
echo " -i - ip output"
echo " -t - tcp output"
echo " -u - udp output"
echo " -r - arp output"
echo " -e - icmp output"
echo " -v - verbose mode (write 'long line' Attributes)"
echo
echo " Example: $0 -c /dev/hme -l 2 -tuvi"
echo " Everything is optional, customize your output!"
echo
}
function get_ip
{
ip_container=`ndd -get /dev/ip \? | sed '1d' | nawk -F"(" '{print $1}'`
printf "\n\nBegin IP Config:\n\n" >&3
for i in $ip_container
do
ip_val=`ndd -get /dev/ip $i | sed -n -e '1p' -e '2,$p'`
var_ip=`echo $ip_val | wc -m`
if (( var_ip < "9" ))
then
print $i"="$ip_val >&3
elif (( var_ip >= "9" )) && (( verbose == "0" ))
then
continue
elif (( var_ip >= "9" )) && (( verbose == "1" ))
then
print $i"="$ip_val >&3
else
echo "error - aborting..."
exit 4
fi
done
printf "\n\nEnd IP Config\n" >&3
}
function get_tcp
{
tcp_container=`ndd -get /dev/tcp \? | sed '1d' | nawk -F"(" '{print $1}'`
printf "\n\nBegin TCP Config:\n\n" >&3
for t in $tcp_container
do
tcp_val=`ndd -get /dev/tcp $t | sed -n -e '1p' -e '2,$p'`
var_tcp=`echo $tcp_val | wc -m`
if (( var_tcp < "9" ))
then
print $t"="$tcp_val >&3
elif (( var_tcp >= "9" )) && (( verbose == "0" ))
then
continue
elif (( var_tcp >= "9" )) && (( verbose == "1" ))
then
print $t"="$tcp_val >&3
else
echo "error - aborting..."
exit 6
fi
done
printf "\n\nEnd TCP Config\n" >&3
}
function get_udp
{
udp_container=`ndd -get /dev/udp \? | sed '1d' | nawk -F"(" '{print $1}'`
printf "\n\nBegin UDP Config:\n\n" >&3
for u in $udp_container
do
udp_val=`ndd -get /dev/udp $u | sed -n -e '1p' -e '2,$p'`
var_udp=`echo $udp_val | wc -m`
if (( var_udp < "9" ))
then
print $u"="$udp_val >&3
elif (( var_udp >= "9" )) && (( verbose == "0" ))
then
continue
elif (( var_udp >= "9" )) && (( verbose == "1" ))
then
print $u"="$udp_val >&3
else
echo "error - aborting..."
exit 7
fi
done
printf "\n\nEnd UDP Config\n" >&3
}
function get_arp
{
arp_container=`ndd -get /dev/arp \? | sed '1d' | nawk -F"(" '{print $1}'`
printf "\n\nBegin ARP Config:\n\n" >&3
for a in $arp_container
do
arp_val=`ndd -get /dev/arp $a | sed -n -e '1p' -e '2,$p'`
var_arp=`echo $arp_val | wc -m`
if (( var_arp < "9" ))
then
print $a"="$arp_val >&3
elif (( var_arp >= "9" )) && (( verbose == "0" ))
then
continue
elif (( var_arp >= "9" )) && (( verbose == "1" ))
then
print $a"="$arp_val >&3
else
echo "error - aborting..."
exit 8
fi
done
printf "\n\nEnd ARP Config\n" >&3
}
function get_icmp
{
icmp_container=`ndd -get /dev/icmp \? | sed '1d' | nawk -F"(" '{print $1}'`
printf "\n\nBegin ICMP Config:\n\n" >&3
for ic in $icmp_container
do
icmp_val=`ndd -get /dev/icmp $ic | sed -n -e '1p' -e '2,$p'`
var_icmp=`echo $icmp_val | wc -m`
if (( var_icmp < "9" ))
then
print $ic"="$icmp_val >&3
elif (( var_icmp >= "9" )) && (( verbose == "0" ))
then
continue
elif (( var_icmp >= "9" )) && (( verbose == "1" ))
then
print $a"="$icmp_val >&3
else
echo "error - aborting..."
exit 11
fi
done
printf "\n\nEnd ICMP Config\n" >&3
}
function get_int
{
int_container=`ndd -get "$int_val" \? | sed '1d' | nawk -F"(" '{print $1}'`
printf "\n\nBegin Interface Config:\n\n" >&3
for int in $int_container
do
int_temp=`ndd -get $int_val $int | sed -n -e '1p' -e '2,$p'`
var_int=`echo $int_temp | wc -m`
if (( var_int < "9" ))
then
print $int"="$int_temp >&3
elif (( var_int >= "9" )) && (( verbose == "0" ))
then
continue
elif (( var_int >= "9" )) && (( verbose == "1" ))
then
print $int"="$int_temp >&3
else
echo "error - aborting..."
exit 12
fi
done
printf "\n\nEnd Interface Config\n" >&3
}
################# Action #################
if (( $# == "0" )) || [[ $1 == "--help" ]]
then
help
exit 0
fi
if (( $# > "12" ))
then
echo "Syntax Error - Too much arguments"
echo
echo
help
exit 13
fi
export PATH=/usr/bin:/usr/sbin
verbose="0"
with_int="0"
int_val="0"
instance_id="0"
instwasset="0"
option_counter="255"
print="0"
want_ip="0"
want_tcp="0"
want_udp="0"
want_arp="0"
want_icmp="0"
want_justint="0"
version="2.0"
while getopts :c:l:aituerhvVp option
do
case $option in
h)
help
exit 0
;;
V)
echo "Version=$version"
exit 0
;;
c)
if [[ -c $OPTARG ]]
then
with_int="1"
int_val="$OPTARG"
else
echo "specified file cannot be an interface (no character file)"
exit 1
fi
;;
l)
instance_id_container=`echo $OPTARG | nawk '{if ($0 < 1024) print $0}'`
if [[ -n $instance_id_container ]]
then
instance_id=$OPTARG
instwasset=1
else
echo "invalid argument for 'l'"
exit 2
fi
;;
a)
option_counter="0"
;;
i)
want_ip="1"
option_counter="1"
;;
t)
want_tcp="1"
option_counter="2"
;;
u)
want_udp="1"
option_counter="3"
;;
r)
want_arp="1"
option_counter="4"
;;
e)
want_icmp="1"
option_counter="5"
;;
v)
verbose="1"
;;
p)
print="1"
;;
:)
echo "no argument for $OPTARG"
exit 9
;;
\?)
echo "Invalid Option given (${OPTARG})"
exit 10
;;
esac
done
# catch user errors
if (( with_int == "0" )) && (( "$instwasset" != "0" ))
then
echo "You cannot specify an instance without interface"
exit 2
elif (( with_int != "0" ))
then
ndd_error=`ndd -set "$int_val" instance "$instance_id"`
# Cause ndd give a text message instead of an non zero exit code
if [[ -n "$ndd_error" ]]
then
echo "incorrect instance or interface"
exit 3
fi
fi
# the decision process
exec 3> ./ntwk.conf
filestart
if (( want_ip == "1" || option_counter == "0" ))
then
get_ip
separator
fi
if (( want_tcp == "1" || option_counter == "0" ))
then
get_tcp
separator
fi
if (( want_udp == "1" || option_counter == "0" ))
then
get_udp
separator
fi
if (( want_arp == "1" || option_counter == "0" ))
then
get_arp
separator
fi
if (( want_icmp == "1" || option_counter == "0" ))
then
get_icmp
separator
fi
if (( with_int != "0" ))
then
get_int
fi
outsize=`wc -l ntwk.conf | nawk '{print $1}'`
if (( $outsize == 1 ))
then
echo 'sorry, you don`t generate any usefull output'
exit 15
else
printf "\nOutput is successfully written in ./ntwk.conf\n"
fi
if (( print == 1 ))
then
if type more > /dev/null 2>&1
then
exec 3<&-
more ntwk.conf
exit 0
else
echo "sorry, cannot find the 'more' binary"
exec 3<&-
exit 16
fi
else
exec 3<&-
exit 0
fi
##############################################################################
### This script is submitted to BigAdmin by a user of the BigAdmin community.
### Sun Microsystems, Inc. is not responsible for the
### contents or the code enclosed.
###
###
### Copyright 2008 Sun Microsystems, Inc. ALL RIGHTS RESERVED
### Use of this software is authorized pursuant to the
### terms of the license found at
### http://www.sun.com/bigadmin/common/berkeley_license.html
##############################################################################