Solved

Nbtstat Command?

Posted on 1998-02-23
19
1,201 Views
Last Modified: 2011-09-20
Hello;
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.
Regards
0
Comment
Question by:trodri
  • 8
  • 8
  • 3
19 Comments
 
LVL 5

Expert Comment

by:dirtdart
Comment Utility
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.
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
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?
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
email me if you wish at mick@owen.wa.com
0
 
LVL 5

Expert Comment

by:dirtdart
Comment Utility
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
               statistics.


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.
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
dirtdart,

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.

0
 
LVL 5

Expert Comment

by:dirtdart
Comment Utility
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.
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
dirtdart, I've written VB code that uses most of the functions but I don't think any return the information trodri is seeking.
0
 

Author Comment

by:trodri
Comment Utility
Can any one make a dll with this functions?
Regards
0
 
LVL 5

Expert Comment

by:dirtdart
Comment Utility
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:dirtdart
Comment Utility
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.

NCBACTION
 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.
 
NCBADDGRNAME
 Adds a group name to the local name table.
 
NCBADDNAME
 Adds a unique name to the local name table.
 
NCBASTAT
 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.
 
NCBCALL
 Opens a session with another name.
 
NCBCANCEL
 Cancels a previous command.
 
NCBCHAINSEND
 Sends the contents of two data buffers to the specified session partner.
 
NCBCHAINSENDNA
 Sends the contents of two data buffers to the specified session partner and does not wait for acknowledgment.
 
NCBDELNAME
 Deletes a name from the local name table.
 
NCBDGRECV
 Receives a datagram from any name.
 
NCBDGRECVBC
 Receives broadcast datagram from any host.
 
NCBDGSEND
 Sends datagram to a specified name.
 
NCBDGSENDBC
 Sends a broadcast datagram to every host on the local area network (LAN).
 
NCBENUM
 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.
 
NCBFINDNAME
 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.
 
NCBHANGUP
 Closes a specified session.
 
NCBLANSTALERT
 Notifies the user of LAN failures that last for more than one minute.
 
NCBLISTEN
 Enables a session to be opened with another name.
 
NCBRECV
 Receives data from the specified session partner.
 
NCBRECVANY
 Receives data from any session corresponding to a specified name.
 
NCBRESET
 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.
 
NCBSEND
 Sends data to the specified session partner.
 
NCBSENDNA
 Sends data to specified session partner and does not wait for an acknowledgment.
 
NCBSSTAT
 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.
 
NCBTRACE
 Activates or deactivates NCB tracing. Support for this command in the system is optional and system-specific.
 
NCBUNLINK
 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.
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
dirtdart, I found exactly the same thing and I am working on the example trodri has asked for - are your providing an example?
0
 
LVL 5

Expert Comment

by:dirtdart
Comment Utility
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.
0
 
LVL 5

Expert Comment

by:dirtdart
Comment Utility
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.
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
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.

0
 

Author Comment

by:trodri
Comment Utility
Sorry, but i need source code working.
Best regards
0
 
LVL 5

Expert Comment

by:dirtdart
Comment Utility
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.

Bye

PS:  In the future, it is acceptable to simply post a comment instead of rejecting the answer if you only need more information.
0
 

Author Comment

by:trodri
Comment Utility
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?
Sorry.
Best regards
0
 
LVL 8

Expert Comment

by:mrmick
Comment Utility
trodri,

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


0
 
LVL 8

Accepted Solution

by:
mrmick earned 430 total points
Comment Utility
Ok, it has been sent.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now