Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Windows Net Use

by Anonymous Monk
on Oct 02, 2014 at 17:58 UTC ( #1102658=note: print w/replies, xml ) Need Help??


in reply to Windows Net Use

here is a kind of quick and dirty utility to use the WMIC NETUSE command to do things. not meant to be pretty - just present the data.

use strict; my %netuse_from_wmic; my @wmic_output=`WMIC NETUSE LIST FULL /FORMAT:CSV`; my @title_data; my $LocalNameIndex; foreach my $wmic_line (@wmic_output) { chomp $wmic_line; $wmic_line=~s/\r$//; next if $wmic_line eq ""; if(0==scalar @title_data) { @title_data=split /,/,$wmic_line; for(my $idx=0;$idx<scalar @title_data;$idx++) { print "$idx=$title_data[$idx]\n"; $LocalNameIndex=$idx if $title_data[$idx]=~/^LocalName$/i; } die "no LocalName found in title" if !defined $LocalNameIndex; } else { my @wmic_netuse_entry=split /,/,$wmic_line; for(my $idx=0;$idx<scalar @title_data;$idx++) { $netuse_from_wmic{uc $wmic_netuse_entry[$LocalNameIndex]}{ +$title_data[$idx]}=$wmic_netuse_entry[$idx]; } } } foreach my $drive (sort keys %netuse_from_wmic) { print "Drive: $drive\n"; foreach my $value (sort keys %{$netuse_from_wmic{$drive}}) { print " $value=$netuse_from_wmic{$drive}{$value}\n"; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1102658]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2019-06-17 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (76 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!