Solved

NBTSTAT -a how to program?

Posted on 1998-01-23
7
783 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
[X]
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
  • 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Trying to figure out group policy inheritance and which settings apply where can be a chore.  Here's a very simple summary I've written which might help.  Keep in mind, this is just a high-level conceptual overview where I try to avoid getting bogge…
An article on effective troubleshooting
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

696 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