Solved

NBTSTAT -a how to program?

Posted on 1998-01-23
7
745 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
Comment Utility
Edited text of question
0
 
LVL 32

Expert Comment

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

Author Comment

by:phj
Comment Utility
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
New My Cloud Pro Series - organize everything!

With space to keep virtually everything, the My Cloud Pro Series offers your team the network storage to edit, save and share production files from anywhere with an internet connection. Compatible with both Mac and PC, you're able to protect your content regardless of OS.

 
LVL 32

Expert Comment

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The Need In an Active Directory enviroment, the PDC emulator provide time synchronization for the domain. This is important since Active Directory uses Kerberos for authentication.  By default, if the time difference between systems is off by more …
This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

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

8 Experts available now in Live!

Get 1:1 Help Now