Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

NBTSTAT -a how to program?

Posted on 1998-01-23
7
765 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

This article is in response to a question (http://www.experts-exchange.com/Networking/Network_Management/Network_Analysis/Q_28230497.html) here at Experts Exchange. The Original Poster (OP) requires a utility that will accept a list of IP addresses …
I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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