Utility code for working with NetBIOS names.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



A utility module for working with NetBIOS names as defined in RFC1001, RFC1002, and RFC883.

Build Status


var NBName = require('netbios-name');

// The following two statements are equivalent
var nbname = new NBName({fqdn: 'foobar.example.com', suffix: 0x20});
var nbname = new NBName({name: 'foobar', scopeId: 'example.com',
                         suffix: 0x20});

if (nbname.error) {
  throw nbname.error;

nbname.name === 'foobar';                           // true
nbname.paddedName === 'foobar         ';            // true
nbname.scopeId === 'example.com';                   // true
nbname.fqdn === 'foobar.example.com';               // true
nbname.suffix === 0x20;                             // true
nbname.usage === 'File Server Service';             // true
nbname.toString() === 'foobar<20>.example.com';     // true

var buf = new Buffer(128);

var res = nbname.write(buf, 0, {});
if (res.error) {
  throw res.error;

var nbname2 = NBName.fromBuffer(buf, 0);
if (nbname2.error) {
  throw nbname2.error;

nbname2.bytesRead === res.bytesWritten;             // true
nbname2.name === nbname.name;                       // true
nbname2.scopeId === nbname.scopeId;                 // true
nbname2.fqdn === nbname.fqdn;                       // true
nbname2.suffix === nbname.suffix;                   // true
nbname2.usage === nbname.usage;                     // true

Class: NetbiosName

This class represents the name of a single NetBIOS node or service. It consists of the following properties:

  • name {String} The short NetBIOS name. This is equivalent to the first label in a fully qualified domain name. The NetBIOS name is restricted to a maximum length of 15 characters.
  • scopeId {String} The scope identifier or domain name that the node belongs to. For example, if the fully qualified domain name is host.example.com, then the scopeId property will be example.com and the name property above will be host.
  • suffix {Number} The trailing suffix byte that combines with the NetBIOS name above to create a 16-byte fixed width field. Microsoft popularized the use of this byte for indicating the type or usage of the node. Typically suffix byte values will be defined and displayed in hex; e.g. 0x00 for workstations or 0x20 for file servers.

In addition to the basic properties, the class also derives the following values as a convenience:

  • paddedName {String} The same as the name field space padded out to 15 characters.
  • fqdn {String} The combination of the name field and the scopeId field.
  • usage {Sring} A human readable string describing the typical usage for the given suffix byte. If the suffix does not match a typical value, then usage will be set to 'unknown'. These usage values are taken from the Microsoft NetBIOS Suffixes knowledge base article.

Finally, instances of NetbiosName can also have additional properties based on how the object was created:

  • error {Error Object} This property will be set if the constructor or fromBuffer() method encounter an error while creating the NetbiosName object. This property should always be checked before using the instance or any of its other properties.
  • bytesRead {Number} This property indicates how many bytes were read from the buffer passed to fromBuffer() in order to create this instance.

Note, all properties are set in the constructor or the fromBuffer() factory method. If you write to one of the properties, don't expect any other values to get updated to reflect the change.

new NetbiosName(opts)

Construct a new NetbiosName instance for a given name and suffix.

  • opts {Object} A hash of named parameters. Accepted options are:
    • fqdn {String} The fully qualified domain name to use.
    • name {String} The short NetBIOS name to use. This is only referenced if fqdn is not present.
    • scopeId {String} The trailing domain name to be combined with the name property. This should not include a leading dot. This is only referenced if fqdn is not present.
    • suffix {Number} The suffix byte value to use. If this is not present then the suffix defaults to 0x00 which typically represents a workstation service.
  • Returns a new NetbiosName instance. Note that if there are any problems the error property of the NetbiosName object will be set. Typically errors only occur if a name is not provided or if its illegal due to length, etc.

NetbiosName.fromBuffer(buf, offset)

Construct a new NetbiosName object from a binary buffer.

  • buf {Buffer Object} The buffer to read the name from. Note, if this name is being read from a message that uses name pointers, the first byte of the buffer must correspond to the start of the message. So don't just slice() to the start of the name since the pointer offsets will be meaningless.
  • offset {Number} The offset from the start of the buffer indicating where to begin reading.
  • Returns a new NetbiosName object instance. Make sure to check the error property on the returned object before using any other properties. Also, see the bytesRead property to determine how much of the buffer was processed by this method.

nbname.write(buf, offset, nameMap)

Write the NetbiosName object instance out to the given buffer.

  • buf {Buffer Object} The buffer to write the name to. Again, if name pointers are going to be used, the start of the buffer must match the start of the overall NetBIOS message.
  • offset {Number} Where to begin writing the name within the buffer.
  • nameMap {Object | null} If provided the location of the name within the buffer will be stored in the nameMap. If the same nameMap is used to write the same name again or a portion of the name, then a name pointer will used to compress the name within the buffer. Passing null will disable the use of name pointers.
  • Returns an Object containing two properties.
    • error {Error Object} If an error occurred during writing this property will be set. The buffer may have been partially modified even if an error occurs.
    • bytesWritten {Number} The number of bytes written to the buffer.


Return a string representation of the NetBIOS name. The format matches the style used by wireshark. For example, a name of foobar, a scope ID of example.com, and suffix of 0x20 would be returned as the string 'foobar<20>.example.com'.

The string returned contains all of the unique information in the name, so it can be reasonably used as the key for a hash.