Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Network Neighborhood and LWP::UserAgent list directory

by LeGo (Chaplain)
on Aug 31, 2001 at 01:52 UTC ( [id://109216]=perlquestion: print w/replies, xml ) Need Help??

LeGo has asked for the wisdom of the Perl Monks concerning the following question:

I am in search of a way to scan a CPU's Network Neighborhood files so that I can then store a list of the files.

In browsers I am able to just type in the IP and see what is being shared via network neighborhood, 'file://i.p.add.ress'. I am unsure on how to go about doing this in perl. I thought that I would be able to do this using LWP::UserAgent becuase of the 'file' option.

I am not sure where to go from what I have. If you could help I would appreciate it. Below is the code I have.

#!/usr/local/bin/perl -w use strict; use LWP::UserAgent; my $ua = new LWP::UserAgent; $ua->agent("Mozilla/8.0 " . $ua->agent); my $req = HTTP::Request->new(GET => 'file://ip/COOLHITS/'); my $res = $ua->request($req); if($res->is_success){ print $res->content; }else{ print "Bad Luck this time\n"; }

As you can see this code looks a lot like LWP's example, but I can't figure out what to do with it. The output I get returned is "Bad Luck this time".

All help is appreciated.

LeGo

Replies are listed 'Best First'.
Re: Network Neighborhood and LWP::UserAgent list directory
by lestrrat (Deacon) on Aug 31, 2001 at 02:06 UTC

    Is this M$ Network Neighborhood stuff? I didn't know about this 'feature' until I read this node, but I would assume this doesn't actually involve HTTP, does it?

    My guess is that since Windoze treats Network Neighborhood files/folders as local, when you type "file://..." the browser is only going to the OS ( i.e., not network activity from the browser's perspective) to ask for the file, thinking that is a local file?

    If so, the reason why LWP fails to find these files is because LWP tries to talk HTTP to find the files on the peer machine, and since a regular Windoze workstation don't come with an HTTP server, the attempt fails.

    I don't have ActivePerl installed on my Win2k so I can't try it, but I'd almost think that on a Network Neighborhood - equipped Win box, you can achieve the same effect by using a regular file open() ? Just a wild guess.

      I am using Win2k and went to try the following...

      #!d:\perl\bin\perl.exe -w use strict; my $dir = 'file:/IP/'; opendir (DIR, $dir) or die "cannot opendir $dir"; foreach (readdir(DIR)){ #do something }

      This gave me the "cannot opendir"... response.

      I do agree with what you are saying with your response but I don't know what to do.

      LeGo

        Why not just use a UNC...

        #!d:\perl\bin\perl.exe -w use strict; my $server = "192.168.0.5"; # or something my $dir = "\\\\$server\\c\$\\temp"; # open c:\temp on $server opendir (DIR, $dir) or die "cannot opendir $dir"; foreach (readdir(DIR)){ #do something }
        I am not sure if this works - I think it does - I know it works if $server is the actual Win32::NodeName(). And I know that you can type "\\ip.address\c$\temp" in the Start > Run dialogue box.

        If this fails, then just share the remote path use Win32::NetResource

        Of course, all this depends on you having read permissions on the remote machine.

        Error: Keyboard not attached. Press F1 to continue.
        I know I sound like a broken record on this, but you would be likely to get a more informative error if your error message included the contents of $! (the last error generated by the OS). This advice is straight out of perlstyle.
Re: Network Neighborhood and LWP::UserAgent list directory
by joefission (Monk) on Aug 31, 2001 at 08:29 UTC
    I agree with $code or die, use the Win32::NetResource module. It should work with or without ADSI.

    Example copied from the Win32::NetResource doc:

    # 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 = undef; GetError($err); warn Win32::FormatMessage($err); } foreach my $href (@$resources) { next if ($$href{DisplayType} != RESOURCEDISPLAYTYPE_SHARE); print "-----\n"; foreach( keys %$href){ print "$_: $href->{$_}\n"; } }

      I've had problems using Win32::NetResource with ActivePerl 5.6.1. Using the module gives compilation errors.

      (To be honest I've never bothered filing a bug report or looking for an upgraded module. I assume there's a fix.)

Re: Network Neighborhood and LWP::UserAgent list directory
by rchiav (Deacon) on Aug 31, 2001 at 04:56 UTC
    Sorry.. I originally posted the answer to the wrong question. This will do the trick for you. It uses ADSI.. but only works on NT and 2000 machines.
    #!/usr/bin/perl -w use strict; use Win32::OLE qw(in); my $i; my $comp = Win32::OLE->GetObject("WinNT://computername/LanmanServer"); foreach $i (in $comp) { print $i->{name}, "\n"; }
    Hope this helps..
    Rich
Re: Network Neighborhood and LWP::UserAgent list directory
by rrwo (Friar) on Aug 31, 2001 at 08:47 UTC

    LWP is the wrong approach, unless you're fetching thrings from the web (http), ftp, and the filesystem/network shares in the same application.

    Also, you won't see hidden shares.

    I think you need to use the Win32::NetResource to get a list of shares, and other related Win32 modules for doing things on Windows networks.

    Check out David Roth's Windows NT: Win32 Perl Programming and Win32 Perl Scripting books for references and a more complete listing of how to do things with with Windows and Windows networking.

Re: Network Neighborhood and LWP::UserAgent list directory
by Beatnik (Parson) on Aug 31, 2001 at 11:22 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://109216]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found