Solved

NBTSTAT -a how to program?

Posted on 1998-01-23
7
772 Views
Last Modified: 2013-12-23
Which network function(s) do I have to use if I what to develop a WIN32 program which has the same functionality as NBTSTAT -a <IP-ADDRESSE>?
0
Comment
Question by:phj
  • 4
  • 3
7 Comments
 

Author Comment

by:phj
ID: 1570624
Edited text of question
0
 
LVL 32

Expert Comment

by:jhance
ID: 1570625
Check the documentation on the NetWkstaXXX family of functions.  These will get you most of the available network services.
0
 

Author Comment

by:phj
ID: 1570626
I have been checking NetWkstaXXX as jhance suggested, but did't find any clue here. I looked at DEJANEWS, where other people have asked the same question, but I did't find any answer here.

The only thing I found was that you have to use gethostbyaddr. I don't have doc for this Winsock function here, but I belive that it will take a given IP-address and in my case use WINS or broadcast to resolve this a hostname.

Perhaps you can use this function together with some NetBIOS calls (fx NCB.STATUS), but still I am not close to a solution.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Expert Comment

by:jhance
ID: 1570627
Maybe you could be more specific about what you are looking for.  NBTSTAT give a bunch of stuff about hosts and shares.  Are you looking to resolve IP addresses to host names?
0
 

Author Comment

by:phj
ID: 1570628
Hi,

Thanks jhance for coming back, this is my first question.

I will try to explane this in some more details.

Exactly what I what to do is to write a program which in a loop looks at all my IP-addresses. Fx NBTSTAT -A 156.136.9.51 will if this a WfW og NT give me the Remote Name table of this PC. I use static IP-addressing so i know in which range the pc's are would be. Also the Computer name (NetBios name) of a given pc is also done in a very strict system.

In this example NBTSTAT -A 156.136.9.51 will give my the following information: IP-address of course, Computer name, User name and MAC addresse. When this program has been running for a while I have a file containg, i hope, 95% off all the IP-addresses in use and there corresponding computer name, user name and MAC-addresse. Whith this file I will be able to update our user administration system which so far only has oneway. (It runs a IBM Mainframe).

Back to the software. I have V-COMM sourcer looked at NBTSTAT and to my surprise it uses the following DLL: WOSCK32, NTDLL, MSVCRT, ADVAPI32, USER32.

In WSOCK32.DLL it uses only function 10 (inet_addr),14 (ntohl) and 1108 (s_perror). None off these are very interresting. So NBTSTAT must do something else.

In a book I have about Windows NT Networkprogramming, there is some examples using the NetBIOS() API, fx NCB.ENUM, NCB.ADAPTER.STATUS, NCB.SESSION.STATUS. If you should use NETBIOS API, why don't NBTSTAT?.

I will reale hope that this will help.

Thanks for this very objectiv view on this problem :-)


0
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 1570629
So I think you want to get 3 things from your IP address. Computername, MAC Address, and user name.  These can be had as follows:

Computername: use gethostbyaddr(), assuming you are using DNS or a HOSTS file, this will get you to the TCP/IP hostname.

MAC Address, here is an example:

From the NETBIOS documentation:


#include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
typedef struct _ASTAT_{    ADAPTER_STATUS adapt;
    NAME_BUFFER NameBuff [30];
}ASTAT, * PASTAT;
ASTAT Adapter;

void main (void)
{    
 NCB ncb;
    UCHAR uRetCode;
    char NetName[50];
    memset( &ncb, 0, sizeof(ncb) );
    ncb.ncb_command = NCBRESET;
    ncb.ncb_lana_num = 0;
    uRetCode = Netbios( &ncb );
    printf( "The NCBRESET return code is: 0x%x \n", uRetCode );
    memset( &ncb, 0, sizeof(ncb) );
    ncb.ncb_command = NCBASTAT;
    ncb.ncb_lana_num = 0;
    strcpy( ncb.ncb_callname, "* " );
    ncb.ncb_buffer = (char *) &Adapter;
    ncb.ncb_length = sizeof(Adapter);
    uRetCode = Netbios( &ncb );
    printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );
    if ( uRetCode == 0 )    {
        printf( "The Ethernet Number is: %02x%02x%02x%02x%02x%02x\n",
                Adapter.adapt.adapter_address[0],
                Adapter.adapt.adapter_address[1],
                Adapter.adapt.adapter_address[2],
                Adapter.adapt.adapter_address[3],
                Adapter.adapt.adapter_address[4],
                Adapter.adapt.adapter_address[5] );
    }
}  


User name:  Use the NetWkstaUserEnum() API function
0
 

Author Comment

by:phj
ID: 1570630
Hi,

Sorry for the delayed response.

This is much more complex than I thought. So after some thoughts I have concluded that the easyest way is to write a dos program which calls NBTSTAT -A <IP ADDRESS>.

So I rest my case :-)


0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief overview to explain gateways, default gateways and static routes OR NO - you CANNOT have two default gateways on the same server, PC or other Windows-based network device. In simple terms a gateway is formed when a computer such as a serv…
Downtime reduced, data recovered by utilizing an Experts Exchange Business Account Challenge The United States Marine Corps employs more than 200,000 active-duty Marines with operations in four continents, all requiring complex networking system…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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