#!/usr/bin/perl #uses ncutil to dump network configuration (sub)tree #written and tested on opendarwin 7.1 #Copyright 2004 Gyepi Sam #All rights reserved. use Getopt::Long our $verbose = 0; our $help = 0; use Getopt::Long; unless (GetOptions("verbose|v" => \$verbose, 'help|h' => \$help)){ &print_usage; exit 1; } if ($help){ &print_help; exit 0; } unshift @ARGV, '/' unless @ARGV; for (@ARGV){ &dump_tree($_); } sub dump_tree { my $root = shift; return unless $root; print $root, "\n"; (my $qroot = $root)=~ s/'/'\\''/g; $qroot = qq['$qroot']; my @properties = read_cmd(qq[ncutil read $qroot]); for my $prop(@properties){ print qq[\t$prop\n]; } print "\n" if @properties; my @children = read_cmd(qq[ncutil list $qroot]); for my $child (@children) { next unless $child; if (my ($index, $name) = $child =~ m/^(\d+)\s+(.+)/){ my $t = $root; $t .= '/' unless $t =~ m:/$:; $t .= $name; &dump_tree($t); } else { warn "cannot parse list entry:[$child]\n"; } } } sub read_cmd { my $cmd = shift; print "command: $cmd\n" if $verbose; my @output = qx{$cmd}; die "($?) cannot run command $cmd. $!\n" if $?; #why on earth are there NULLs in the output? tr/\000//d for @output; chomp @output; return @output; } sub print_usage { print STDERR < ...] usage $0 --help | -h EOF } sub print_help { print_usage; print STDERR <