Nbtstat Command?

Can anyone tell me how to, in VB, make an app that give me the same info that the nbtstat -A ipaddress commnand?
Code needed.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You're probably not going to find a straight VB solution for this one.  Most of the API calls needed to get that information only work in C because they deal with data types not available in VB.  Not only this, but they only work on NT.  If you (or anyone you know) knows C, you could write a wrapper dll to contain all the functions and take care of the conversion for you.  This is a project I have thought about several times, but just haven't had time to do.
trodri, exactly what do you want to do?  I'm not familiar with nbtstat, however, I am pretty good at getting any info from my NT server that I want via VB5.  Are you trying to query a DNS server?
email me if you wish at mick@owen.wa.com
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Just for info, mick, here is what the nbtstat command does.

Displays protocol statistics and current TCP/IP connections using NBT
(NetBIOS over TCP/IP).

NBTSTAT [-a RemoteName] [-A IP address] [-c] [-n]
        [-r] [-R] [-s] [-S] [interval] ]

  -a   (adapter status) Lists the remote machine's name table given its name
  -A   (Adapter status) Lists the remote machine's name table given its
                        IP address.
  -c   (cache)          Lists the remote name cache including the IP addresses
  -n   (names)          Lists local NetBIOS names.
  -r   (resolved)       Lists names resolved by broadcast and via WINS
  -R   (Reload)         Purges and reloads the remote cache name table
  -S   (Sessions)       Lists sessions table with the destination IP addresses
  -s   (sessions)       Lists sessions table converting destination IP
                        addresses to host names via the hosts file.

  RemoteName   Remote host machine name.
  IP address   Dotted decimal representation of the IP address.
  interval     Redisplays selected statistics, pausing interval seconds
               between each display. Press Ctrl+C to stop redisplaying

I don't know of any way to duplicate these functions except with the WNet API calls, and I can't think of any way to port those to VB since they all use wide character strings, but if you know a way, I'd certainly be interested in seeing it.  I have been trying essentially this same thing for a while now.

That's why I was so upset after buying Appleman’s book that provided a (garbage) dll wrapper.  All of Dan's wrappers can be duplicated in VB.  I think Dan used VERY POOR judgement in providing a wrapper of functions that could have been written in VB - (I have to assume he didn't know how to write the VB equivalents).  I expect more from a book that promises to put it all in VB terms!

Use of the WNet functions is not a problem.  By the way, WNet functions don't necessarily use wide character strings.  Name a function, I'll provide an example of it's use.

Ok.  I didn't realize that WNet functions didn't need wide character.  The only reference I have for them is the Win32Sdk, and all the declarations there use LPWSTR.  I don't know how to convert that to VB, but if you could do it, then that would be the answer to this question.  The WNet functions provide all the information needed to get the information provided by nbstat.

As far as Appleman's book, I haven't read the newest version.  I have the VB4 version, which I consider to be an extremly good starting reference for someone just learning API calls.  I do, however, agree that the wrapper dll is unnecessary, especially with the advent of AddressOf in VB5.  That makes almost any call possible.

Anyway, if you can translate the WNet functions, then this question is yours.
dirtdart, I've written VB code that uses most of the functions but I don't think any return the information trodri is seeking.
trodriAuthor Commented:
Can any one make a dll with this functions?
I could, but it might take a bit of time.  If you want to talk to me about it, my email is dirtdart01@yahoo.com
I think I found exactly what you are looking for.  The Netbios API call handles most types of netbios requests.

Type NCB
        ncb_command As Integer
        ncb_retcode As Integer
        ncb_lsn As Integer
        ncb_num As Integer
        ncb_buffer As String
        ncb_length As Integer
        ncb_callname As String * NCBNAMSZ
        ncb_name As String * NCBNAMSZ
        ncb_rto As Integer
        ncb_sto As Integer
        ncb_post As Long
        ncb_lana_num As Integer
        ncb_cmd_cplt As Integer
        ncb_reserve(10) As Byte ' Reserved, must be 0
        ncb_event As Long
End Type

Declare Function Netbios Lib "netapi32.dll" (pncb As NCB) As Byte

The NCB data structure passes commands to this call and returns values from the call.  I don't completly understand its working, but here is a list of actions you can perform with it.

 Enables extensions to the transport interface. NCBACTION commands are mapped to TdiAction. When this code is specified, the ncb_buffer member points to a buffer to be filled with an ACTION_HEADER structure, which is optionally followed by data. NCBACTION commands cannot be canceled by using NCBCANCEL.
 Adds a group name to the local name table.
 Adds a unique name to the local name table.
 Retrieves the status of the adapter. When this code is specified, the ncb_buffer member points to a buffer to be filled with an ADAPTER_STATUS structure, followed by an array of NAME_BUFFER structures.
 Opens a session with another name.
 Cancels a previous command.
 Sends the contents of two data buffers to the specified session partner.
 Sends the contents of two data buffers to the specified session partner and does not wait for acknowledgment.
 Deletes a name from the local name table.
 Receives a datagram from any name.
 Receives broadcast datagram from any host.
 Sends datagram to a specified name.
 Sends a broadcast datagram to every host on the local area network (LAN).
 Enumerates LAN adapter (LANA) numbers. When this code is specified, the ncb_buffer member points to a buffer to be filled with a LANA_ENUM structure.
 Determines the location of a name on the network. When this code is specified, the ncb_buffer member points to a buffer to be filled with a FIND_NAME_HEADER structure followed by one or more FIND_NAME_BUFFER structures.
 Closes a specified session.
 Notifies the user of LAN failures that last for more than one minute.
 Enables a session to be opened with another name.
 Receives data from the specified session partner.
 Receives data from any session corresponding to a specified name.
 Resets a LAN adapter. An adapter must be reset before any other NCB command that specifies the same number in the ncb_lana_num member will be accepted.
 The IBM NetBIOS 3.0 specification documents several NCB_RESET NCB’s. Win32 implements the NCB.RESET using the dynamic link routine interface. Particular values can be passed in specific bytes of the NCB, more specifically:
 · If ncb_lsn is not 0x00, all resources associated with ncb_lana_num are to be freed.
 · If ncb_lsn is 0x00, all resources associated with ncb_lana_num are to be freed, and new resources are to be allocated. The ncb_callname[0] byte specifies the maximum number of sessions, and the ncb_callname[2] byte specifies the maximum number of names. A nonzero value for the ncb_callname[3] byte requests that the application use NAME_NUMBER_1.
 Sends data to the specified session partner.
 Sends data to specified session partner and does not wait for an acknowledgment.
 Retrieves the status of the session. When this value is specified, the ncb_buffer member points to a buffer to be filled with a SESSION_HEADER structure, followed by one or more SESSION_BUFFER structures.
 Activates or deactivates NCB tracing. Support for this command in the system is optional and system-specific.
 Unlinks the adapter.
If you need more information, let me know, but I'll have to translate everything from C, because I don't have any VB source code readily available.
dirtdart, I found exactly the same thing and I am working on the example trodri has asked for - are your providing an example?
I wasn't going to unless he asked for one, but I've already got a very small sample worked up where I tested this with VB.  Doesn't really do much but make sure the call is working correctly.  As I said, I was just going to wait and see what he needs, since I don't have a lot of time for extra coding.
Maybe we should agree to split this one.  If trodri wishes, and he likes the answer, he can award one of us 200 on this one, and then give a sham 200 point question to the other.
dirtdart, it doesn't work that way.  You've locked the question by posting the documentation on an API function.  I find this a bit frustrating because you haven't provided any information on how to get the "same info that the nbtstat -A ipaddress command?" (the question).

This isn't about the points - go ahead and answer the question.

trodriAuthor Commented:
Sorry, but i need source code working.
Best regards
Well, since mick's got the spare time to write it, I guess the question's his.  I simply don't have time to write an entire networking program for you.


PS:  In the future, it is acceptable to simply post a comment instead of rejecting the answer if you only need more information.
trodriAuthor Commented:
ok, i'm waiting for micks'code, no problem.
But, in my question, you can see "CODE NEEDED". Then, why you post an answer if you don't have time to write the code?
Best regards

please send me an email explaining exactly what information you wish to obtain at mick@owen.wa.com

Ok, it has been sent.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.