Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Scanning for windows shares

by Anonymous Monk
on Jun 23, 2003 at 19:37 UTC ( #268297=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi would anyone have any code or experience scanning a network for windows shares? The end goal of this script is to be able to brows a windows network showing all the shares in increasing depth as each share is displayed. any help would be really appreciated, thanks, --Quelance

Replies are listed 'Best First'.
Re: Scanning for windows shares
by Solo (Deacon) on Jun 23, 2003 at 20:52 UTC
    Assuming you're scanning from a Win32 box, check out Win32::NetResource for a starting point.

    ...okay, it looks like searches aren't working today, so here's the POD excerpt:

    # # This example displays all the share points in the entire # visible part of the network. # use strict; use Win32::NetResource qw(:DEFAULT GetSharedResources GetError); my $resources = []; unless(GetSharedResources($resources, RESOURCETYPE_ANY)) { my $err; GetError($err); warn Win32::FormatMessage($err); } foreach my $href (@$resources) { next if ($$href{DisplayType} != RESOURCEDISPLAYTYPE_SHARE); print "-----\n"; foreach( keys %$href){ print "$_: $href->{$_}\n"; } }


    Well, I suppose I could hotwire this thing.
      Right, perfect, thanks. Sorry, saying what OS would help eh :) - Windows. thanks everyone, --Quelance
Re: Scanning for windows shares
by mattr (Curate) on Jun 24, 2003 at 07:56 UTC
    I didn't catch what OS you are on. Anyway I've used LinNeighborhood and transitmount on linux. You can then scan through the mnt directory, but you should be careful about code pages, check your samba. On NT I have a program which scans folders on a remote machine which is mounted over the LAN as a local drive which solves the problem and is pretty fast. But without mounting, perhaps the first post is best.
Re: Scanning for windows shares
by zeitgheist (Novice) on Jun 24, 2003 at 03:22 UTC

    Have a peek-a-boo at phynd.


Re: Scanning for windows shares
by Massyn (Hermit) on Jun 23, 2003 at 22:26 UTC

    Sometimes the answer is an obvious one. Try net view \\<SERVERNAME> in a DOS box, assuming you have some NT permissions already on this box.

      This is not that good of a solution because you will still need some way to enumerate all the Windows type (meaning including Samba) machines on the network.

      Check out the resource above, and the rest of Dave Roth's site. There should be something there.

      Figuring out how to query a browse master might also get you some good results too.

      "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
      from command prompt (win32) NET VIEW /WORKGROUP:wkgrpname
      where wkgrpname is the workgroup name you want to see computer names on. then do NET VIEW \\computername or NET VIEW \\ip_address to view shares on particular machines. This will come back with an error if a computer doesn't have sharing turned on. If it is sharing, but no shares, it will still come back with IPC share and some other info. Of course, from perl, just put the commands in backticks, assigning return value to variables, like so $return_val = `NET VIEW \\BOBs_PC`; if ($return_val)...etc.
      you can even view domains: NET VIEW \DOMAIN:domainname

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://268297]
Front-paged by tye
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2018-07-19 00:29 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (398 votes). Check out past polls.