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

@network-utils/arp-lookup

v2.1.0

Published

A simple ARP util to map an IP address to a MAC address and vice versa.

Downloads

3,986

Readme

arp-lookup

checks code style: prettier

About

arp-lookup is a simple ARP utility to map an IP address to a MAC address and vice versa.

Vendor information has been removed from v2 in favor of @network-utils/vender-lookup
Please see the CHANGELOG.md for the full list of breaking changes

Installation

$ npm install @network-utils/arp-lookup

Usage

Example

import arp from '@network-utils/arp-lookup'
// Or
import {toMAC, toIP, ...} from '@network-utils/arp-lookup'

// Retrieve the corresponding IP address for a given MAC address
await arp.toIP('04-A1-51-1B-12-92') // Or '04:a1:51:1b:12:92' (any valid MAC format)
// Result: "192.168.2.47"

// Retrieve the corresponding MAC address for a given IP address
await arp.toMAC('192.168.2.47')
// Result: "04:a1:51:1b:12:92" 👈🏼 All MAC addresses are normalized to this format

arp.isMAC('04-a1:51:1B-12-92') // true
arp.isMAC('not:a:mac') // false

arp.isIP('192.168.2.47') // true
arp.isIP('not.an.ip') // false

// Note: Unavailable on darwin based systems.
await arp.isType('dynamic', '192.168.2.47') // true
await arp.isType('dynamic', '04:a1:51:1b:12:92') // true
await arp.isType('static', '192.168.2.255') // true
await arp.isType('static', 'ff:ff:ff:ff:ff:ff') // true
await arp.isType('undefined', '0.0.0.0') // true

// Note: `type` property is always set to `"unknown"` on darwin systems
await arp.getTable()
// Result:
[
    { ip: '192.168.137.255', mac: 'ff:ff:ff:ff:ff:ff', type: 'static' },
    { ip: '224.0.0.22', mac: '01:00:5e:00:00:16', type: 'static' },
    { ip: '224.0.0.251', mac: '01:00:5e:00:00:fb', type: 'static' },
    { ip: '224.0.0.252', mac: '01:00:5e:00:00:fc', type: 'static' },
    { ip: '239.255.255.250', mac: '01:00:5e:7f:ff:fa', type: 'static' },
    { ip: '192.168.2.1', mac: '04:a1:51:1b:12:92', type: 'dynamic' },
    { ip: '192.168.2.3', mac: '1a:b1:61:2f:14:72', type: 'dynamic' },
    { ip: '192.168.2.255', mac: 'ff:ff:ff:ff:ff:ff', type: 'static' },
    { ip: '224.0.0.2', mac: '01:00:5e:00:00:02', type: 'static' },
    ...
]


// Note: `type` property is always set to `"unknown"` on Unix systems
await arp.fromPrefix('01:00:5e')
// Result:
[
    { ip: '224.0.0.22', mac: '01:00:5e:00:00:16', type: 'static' },
    { ip: '224.0.0.251', mac: '01:00:5e:00:00:fb', type: 'static' },
    { ip: '224.0.0.252', mac: '01:00:5e:00:00:fc', type: 'static' },
    { ip: '239.255.255.250', mac: '01:00:5e:7f:ff:fa', type: 'static' },
    { ip: '224.0.0.2', mac: '01:00:5e:00:00:02', type: 'static' },
    ...
]

getTable(): Promise<IArpTable>

Returns a promise containing the parsed output of $ arp -a with the addition of a vendor field.
Note that the type property is always set to "unknown" on Unix systems


toMAC(ip: string): Promise<string | null>

Returns a promise containing the MAC that relates to ip or null if a match couldn't be made.
Throws an "Invalid IP" error if ip is not a valid IP address


toIP(mac: string): Promise<string | null>

Returns a promise containing the IP that relates to mac or null if a match couldn't be made.
Throws an "Invalid MAC" error if mac is not a valid MAC address


fromPrefix(prefix: string): Promise<IArpTableRow[]>

Returns any devices on the network with the specified MAC prefix, or an empty array if none exist.
Throws an "Invalid Prefix" error if prefix is not a valid MAC address prefix


getType(address: string): Promise<'static' | 'dynamic' | 'unknown' | 'undefined'>

  • address can be any valid IP or MAC address

Returns a promise containing a string which indicates the record type.
This method is useless on Unix based systems because $ arp -a doesn't return the type for an address
Throws an "Invalid address" error if address is not a valid IP or MAC address


isType(type: 'static' | 'dynamic' | 'unknown' | 'undefined', address: string): Promise<boolean>

  • address can be any valid IP or MAC address

Returns a promise containing a boolean which indicates the record for address is type.
Pass type = "undefined" to determine if a record for address exists or not.
This method is useless on Unix based systems because $ arp -a doesn't return the type for an address
Throws an "Invalid address" error if address is not a valid IP or MAC address


isMAC(mac: string): boolean

Checks if a MAC address is valid


isPrefix(prefix: string): boolean

Checks if a MAC address prefix is valid


isIP(ip: string): boolean

Checks if an IP address is valid


IArpTableRow

IArpTableRow {
  ip: string
  mac: string
  type: 'static' | 'dynamic' | 'unknown'
}

IArpTable

An array of IArpTableRow's.

type IArpTable = IArpTableRow[]

Testing

$ git clone https://github.com/justintaddei/arp-lookup.git
$ cd arp-lookup
$ npm install
$ npm test

License

MIT