npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

netbios-name-service

v0.3.2

Published

NetBIOS name service implementation written in Javascript.

Downloads

14

Readme

netbios-name-service

A 100% javascript implemention of the NetBIOS name service defined in RFC1001 and RFC1002.

Example

var serv = new Service();

serv.start(function() {
  serv.on('added', function(opts) {
    console.log('ADDED: [' + opts.name + '] [' + opts.suffix + '] [' +
                opts.address + ']');
  });

  serv.on('removed', function(opts) {
    console.log('REMOVED: [' + opts.name + '] [' + opts.suffix + ']');
  });

  serv.on('error', function(error) {
    console.log('ERROR: [' + error + ']');
  });

  var name = 'VMWINXP.example.com';
  serv.find({name: name, suffix: 0x00}, function(error, address) {
    console.log('FIND: [' + name + '] resulted in [' + address + ']');
  });

  var name2 = 'FOOBAR.example.com';
  serv.add({
    name: name2,
    suffix: 0x00,
    ttl: 3600,
  }, function(error, success) {
    console.log('ADD: [' + name2 + '] resulted in [' + success + ']');
  });

  var badName = 'THISISTOOLONGFORNETBIOS.example.com'
  serv.find({name: badName, suffix: 0x00}, function(error, address) {
    console.log('FIND: returned error [' + error + ']');
    address === null;   // true
  });
});

Limitations

This module provides a useful set of functionality from the RFCs, but it is still a work in progress.

Please be aware of the following limitations:

  • The name service currently only operates in broadcast mode allowing you to interact with peer nodes on the local network. The point-to-point, mixed, and hybrid modes are not yet implemented. These would allow the service to interact with a name server such as WINS.
  • Group names are supported, but not tested yet. In particular, it is likely that you will only be notified of the first IP found and have no way of finding the full list of addresses for nodes.
  • Requesting status from a node with a large number of names will currently result in an error. In these cases the message may not fit within a UDP packet. According to the RFC the packet should be marked as truncated and re-requested over TCP. Neither of these actions are currently implemented.
  • The service has only been lightly tested on networks with a few nodes. In particular, many of the name conflict corner cases have not been tested in a live environment and may contain hidden issues.
  • The API should be considered unstable as it may change in future versions.

Feedback, testing help, and pull requests welcome.

Class: NetbiosNameService

new NetbiosNameService(options)

Construct a new NetbiosNameService object. The service will not be able to send or receive messages until the start() method is called.

  • options {Object}
    • bindAddress {String | null} The local IPv4 address to use when creating the UDP socket and TCP server. Defaults to binding to '0.0.0.0'.
    • broadcastAddress {String | null} The IPv4 address to use when broadcasting UDP packets. Defaults to '255.255.255.255'.
    • defaultTtl {Number | null} The default time-to-live value to use for names registered with the add() method. Defaults to 3600.
    • tcpDisable {Boolean | null} Disable TCP operations. This mainly prevents other nodes from contacting the service on TCP. Defaults to false.
    • tcpPort {Number | null} Specify the port to use when binding the TCP server. Defaults to 137.
    • tcpServer {Object | null} Provide an existing TCP server that has already been bound. The service will not open a new server and therefore will ignore the tcpPort setting. Note, the tcpDisable option takes precendence and will cause this server object to be ignored. Also, when the service stop() method is called the server will be closed.
    • udpPort {Number | null} Specify the port to use when opening the UDP socket. Defaults to 137.
    • udpSocket {Object | null} Provide an existing UDP socket instead of creating a new one on start(). If this is provided the udpPort option will be ignored. This socket will be closed when the stop() method is called.

service.start(callback)

Start the NetbiosNameService by opening the UDP socket and creating the TCP server.

  • callback {Function | null} Callback issued when the service has fully started.

service.stop(callback)

Stop the NetbiosNameService by clearing the local name map, the remote name cache, and stopping the network services. This will cause removed events to be fired for existing names.

  • callback {Function | null} Callback issued when the service has fully stopped.

service.add(options, callback)

Register the given name for the local NetBIOS node.

  • options {Object}
    • name {String} The NetBIOS name to register for the local node. This name can be a fully qualified domain name, but the first part must be 15 characters or less. Longer names will result in failure and an 'error' event being issued.
    • suffix {Number} The suffix byte indicating the type of the node.
    • address {String | null} The address to use for the local node. Defaults to the bindAddress passed in the new NetbiosNameService() options or the first non-internal, IPv4 address returned by os.networkInterfaces().
    • group {Boolean | null} Indicate if the name should registered as part of a group. Defaults to false.
    • ttl {Number | null} Specify the time-to-live for this name. Defaults to the defaultTtl value passed in the new NetbiosNameService() options.
  • callback {Function | null} Callback issued when the requested name has been successfully added as a local node or definitively failed.
    • error {Object} The Error object associated with any exception conditions and null if none occurred. Note, the add() call can still fail due to a name conflict and set the success argument false without passing an error. The error is more for things like malformed packets and network errors.
    • success {Boolean} True if the name was successfuly registered for the local node. False if the name is already in use on the network by a conflicting node.
    • conflictAddress {String} The IP address of the NetBIOS node that currently owns the specified name. null if no conflict is detected.

service.remove(options, callback)

Deregister the given name from the local NetBIOS node.

  • options {Object}
    • name {String} The NetBIOS name to remove that has been registered for the local node with a previous call to add().
    • suffix {Number} The suffix byte indicating the node type that was previously used when registering the name.
  • callback {Function | null} Callback issued when the requested name has been successfully deregistered for the local node.
    • error {Object} The Error object associated with any exceptional conditions.

service.find(options, callback)

Search for a NetBIOS name with the given name.

  • options {Object}
    • name {String} The NetBIOS name to find.
    • suffix {Number} The suffix byte indicating the type of node to find.
  • callback {Function} Callback issued when the specified name has been found or the service has failed the request.
    • error {Object} The Error object associated with any exceptional conditions.
    • node {Object} The found NetBIOS node information or null if the search failed.
      • name {String} The NetBIOS name of the node.
      • suffix {Number} The suffix byte indicating the type of the node.
      • address {String} The IPv4 address for the node.
      • group {Boolean} A flag indicating if the found name is a group or unique name.
      • ttl {Number} The time-to-live of the node.
      • type {String} The mode of the node such as 'broadcast' or 'hybrid'.

service.on('added', node)

An event emitted when either a local is registered or a remote name is discovered.

  • node {Object}
    • name {String} The NetBIOS name of the node.
    • suffix {Number} The suffix byte indicating the type of the node.
    • address {String} The IPv4 address for the node.
    • group {Boolean} A flag indicating if the found name is a group or unique name.
    • ttl {Number} The time-to-live of the node.
    • type {String} The mode of the node such as 'broadcast' or 'hybrid'.

service.on('removed', node)

An event emitted when either a local name is deregistered or remote name is removed either due to release or cache expiration.

  • node {Object}
    • name {String} The NetBIOS name of the node.
    • suffix {Number} The suffix byte indicating the type of the node.
    • address {String} The IPv4 address for the node.
    • group {Boolean} A flag indicating if the found name is a group or unique name.
    • ttl {Number} The time-to-live of the node.
    • type {String} The mode of the node such as 'broadcast' or 'hybrid'.

service.on('error', error)

An event emitted when unhandled exceptional conditions occur. Normally this will only be things like failing to bind network sockets, etc.

  • error {Object} The Error object