[jcifs] Reusing NetServerEnum outside of SmbFile?

Marcus Crafter crafterm at managesoft.com
Wed Jul 21 12:56:17 GMT 2004

Hi Eric,

Firstly, thanks for your quick reply. :)

On Wed, 2004-07-21 at 01:29, Eric Glass wrote:
> > Ideally I'd like to be able to call SmbFile.sendTransaction(req, resp)
> > and be able to inspect the response results[] array in my application.
> > 
> > Any thoughts?
> > 
> What information are you looking to get?  If you are just looking for
> server/workgroup names, you can probably use jcifs.smb.SmbFile; doing:
>     SmbFile[] files = new SmbFile("smb://").listFiles();
> should give you a list of workgroups/domains; you can do a listFiles()
> on each of those to get the servers in the workgroup.

Essentially I'd like to be able to get a list of machines in a given
domain/workgroup - and read the ServerInfo101 structure details
for each machine in that list, ie. name, major/minor version, device
role, etc.

> If you are looking for more detailed information (similar to what the
> MSDN NetServerEnum call would provide), the jcifs-ext package has an
> implementation of much of the network management stuff:
>     http://sourceforge.net/projects/jcifs-ext/


> Be forewarned that a lot of this may be buggy; I've had other
> priorities and haven't gotten back to touching it up properly.  It may
> work for your needs, though, and is similar in usage to the MSDN
> equivalents.  You would do something like this:
>     String target = "MYSERVER"; // server or domain to contact
>     ServerManagement management = new ServerManagement(target);
>     int infoLevel = 1; // information level 1
>     int serverType = ServerConstants.SV_TYPE_SQLSERVER;
>     ServerInfo[] info = management.netServerEnum(infoLevel,
>             serverType, "MYDOMAIN");
>     for (int i = 0; i < info.length; i++) {
>         ServerInfo1 info1 = (ServerInfo1) info[i];
>         System.out.println(info1.name + ": " + info1.comment);
>     }
> This should contact "MYSERVER" and ask it for all SQL servers in
> "MYDOMAIN", printing the server name and comment.

This looks very similar to what I need to do - thanks *very* much for
the code fragment and pointer to the jcifs-ext project.

>From what I can see briefly browsing the jcifs-ext code all I'd need to
is use an SV_TYPE_ALL - and would then be able to read the data from the
resultant ServerInfo1[] array.

Great news.



PS. Looking at the MSDN ServerInfo101 structure and the JCIFS-EXT
ServerInfo1 class, there seems to be a field missing for the
sv101_platform_id value - is this right?

     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   ManageSoft Corporation
     $       o_)$$$:   Frankfurt am Main, Germany
     ;$,    _/\ &&:'
       '     /( &&&

More information about the jcifs mailing list