net-toolkit.js
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Net-Toolkit.js

Collection of Tools for Network interaction

Quickstart

// import Net-Toolkit
const netJS = require('net-toolkit.js');

// starting async function
async function start () {

    // we want to get our local ipv4 address
    console.log( await netJS.getLocalIpv4() );

    // we want to check if it's the localhost
    console.log( await netJS.isLocalhost(await netJS.getLocalIpv4()) );

    // we want to get all connected client in the local networks and their open ports (within a range of 0 to 100) with a timeout of a 1000 milliseconds
    console.log( await netJS.getOpenPortsOnLocalNetworkInRange( 0, 100, 1000) );
}

// let's start the function
start();

Documentation

Please note, that the functions are asynchronous or return a promise

getLocalIpv4

With this function you can get the ipv4 address of the local machine


@returns local ipv4 address
    const localIpv4 = await netJS.getLocalIpv4();

getLocalIpv6

With this function you can get the ipv6 address of the local machine


@returns local ipv6 address
    const localIpv6 = await netJS.getLocalIpv6();

getLocalIpv4s

With this function you can get an array of ipv4 adresses of the local machine


@returns array of local ipv4 adresses
    const localIpv4s = await netJS.getLocalIpv4s();

getLocalIpv6s

With this function you can get an array of ipv6 adresses of the local machine


@returns array of local ipv6 adresses
    const localIpv6s = await netJS.getLocalIpv6s();

getLocalIpv4AndIpv6

With this function you can get an object containing the ipv4 and ipv6 addresses


@returns object containing ipv4 and ipv6 addresses
    const adressObjects = await netJS.getLocalIpv4AndIpv6();

getExternalIpv4

With this funcion you can get the external ipv4 address of the local machine


@returns external ipv4
    const externalIpv4 = await netJS.getExternalIpv4();

getExternalIpv6

With this funcion you can get the external ipv6 address of the local machine


@returns external ipv6
    const externalIpv6 = await netJS.getExternalIpv6();

isConnected

With this function you can check if the local machine is connected to the internet


@returns true if the local machine is connected
    const isConnected =  await netJS.isConnected();

checkHttp

With this function you can check if a special ipAdress is reachable with http on given port


@param ip adress to check
@param port to check
@returns true if the given ip adress and port are reachable with http
    const httpCheck = await netJS.checkHttp(ip, port);

checkWs

With this function you can check if a special ipAdress is reachable with webSocket on given ports


@param ip adress to check
@param port to check
@returns true if the given ip adress and port are reachable with webSocket
    const wsCheck = await netJS.checkWs(ip, port);

getIpArrayFromHostname

With this function you can get an array of Objects containing IP address and belonging family from a hostname by looking up on the dns


@param hostname
@returns an array of IP addresses
    const ips = getIpArrayFromHostname(hostname);
    /*
        Out for 'google.com' as hostname
        { address: '142.250.185.78', family: 4 },
        { address: '2a00:1450:4001:80e::200e', family: 6 }
    */

getIpv4FromHostname

With this function you can get the Ipv4 adress from a hostname by looking up on the dns


@param hostnames
@returns ipv4 adress
    const ip = getIpv4FromHostname(hostname);

getIpv6FromHostname

With this function you can get the Ipv6 address from a hostname by looking up on the dns


@param hostname
@returns ipv6 adress
    const ip = getIpv4FromHostname(hostname);

getIpv4FromIpv6

With this function you can get the Ipv4 adress from an ipv6 adress by looking up in the dns


obviously it only works if an ipv4 is registered
@param ipv6
@returns ipv4
    const ipv4 = await netJS.getIpv4FromIpv6(ipv6);

getIpv6FromIpv4

With this function you can get the Ipv6 adress from an ipv6 adress by looking up in the dns


obviously it only works if an ipv6 is registered
@param ipv6 @returns ipv4
    const ipv6 = await netJS.getIpv6FromIpv4(ipv4);

getHostnameFromIpv4

With this function you can get the Ipv6 adress from an ipv4 adress by looking up in the dns


obviously it only works if an hostname is registered
@param ipv4
@returns hostname
    const hostname = await netJS.getHostnameFromIpv4(ipv4);

getHostnameFromIpv6

With this function you can get the Ipv6 adress from an ipv6 adress by looking up in the dns


obviously it only works if an hostname is registered
@param ipv6
@returns hostname
    const hostname = await netJS.getHostnameFromIpv6(ipv6);

getMacAdresses

With this function you can get an Array of Mac Adresses


@returns macAdress
    const macAdresses = await netJS.getMacAdresses();

getAllIpv4Adresses

With this function you can get an Array of all possible Ipv4 Adresses


@param ipv4
@returns array of all possible Ipv4 Adresses in typical local network
    const allIpv4Adresses = await netJS.getAllIpv4Adresses(ipv4);

getDevices

With this function you can get an Array of all devices connected to the local network


@param timeout in milliseconds
@returns array of devices connected to the local network
    const devices = await netJS.getDevices(timeout);

getGateways

With this function you can get an array of all the gateways connected to the typical local network


@returns array of gateways connected 100to the typical local network
    const gateways = await netJS.getGateways();

getNetmasks

With this function you can get an array of all the netmasks of the connected local networks


@returns array of all the netmasks of the connected local networks
    const netmasks = await netJS.getNetmasks();

pingIp

With this function you can ping an ip adress


@param ip adress
@param timeout in milliseconds
@returns data result of ping
    const ping = netJS.ping(ip, timeout)

checkPingIp

With this function you can check if an ip adress is reachable


@param ip adress
@param timeout in milliseconds
@returns true if the given ip adress is reachable
    const ping = await netJS.checkPingIp(ip, timeout)

isLocalhost

With this function you can check if an ip adress is localhost


@param ip adress
@returns true if the given ip adress is localhost
    const localhost = await netJS.isLocalhost(ip)

getLocalIpAdressesWithSpecifiedOpenPort

With this function you can get an array of all local ip adresses with specified open port


@param port
@returns array of all local ip adresses with specified open port
    const localIpAdressesWithSpecifiedOpenPort = await netJS.getLocalIpAdressesWithSpecifiedOpenPort(port)

getOpenPortsOfIpInRange

With this function you can get an array of all open ports of an ip adress in range


@param ip adress
@param startPort
@param endPort
@param timeout in milliseconds
@returns array of all open ports of an ip adress in range
    const openPortsOfIpInRange = await netJS.getOpenPortsOfIpInRange(ip, startPort, endPort, timeout);

getOpenPortsOfIp

With this function you can get an array of all open ports of an ip adress


@param ip adress
@param timeout in milliseconds
@returns array of all open ports of an ip adress
    const openPortsOfIp = await netJS.getOpenPortsOfIp(ip, timeout)

getOpenPortsOnLocalNetworkInRange

With this function you can get an array of all open ports of the local network in range and the belonging ip adresses


@param startPort
@param endPort
@param timeout in milliseconds
@returns array of all open ports of the local network in range
    const openPortsOnLocalNetworkInRange = await netJS.getOpenPortsOnLocalNetworkInRange(startPort, endPort, timeout)

getOpenPortsOnLocalNetwork

With this function you can get an array of all open ports of the local network and the belonging ip adresses


@param timeout in milliseconds
@returns array of all open ports of the local network
    const openPortsOnLocalNetwork = await netJS.getOpenPortsOnLocalNetwork(timeout)

getLocalNetworkCidr

With this function you can get all the local network cidr


@returns all local network cidr
    const localNetworkCidr = await netJS.getLocalNetworkCidr()

Future support


Changelog

v.1.2.0

  • fixed bug again :(

v1.1.6

  • fixed Documentation
  • hopefully fixed all stuff

v1.1.5

  • fixed Documentation
  • fixed isLocalhost
  • changed ip family, because it didnt worked properly for me, because somewhat idk

v1.1.4

  • finally fixed the fixed non working imports
  • fixed stuff in documentation

v1.1.2

  • fixed documentation
  • fixed isLocalhosts
  • fixed import

v1.1.1

  • reverted to require
  • added future list

v1.1.0

  • fixed documentation

v1.0.9

  • added v to changelog v1.0.7

v1.0.8

  • changed to module.exports

v1.0.7

  • Changed from require to import
  • added Documentation for all functions
  • added getting array of local ip Adresses (ipv4 and ipv6)
  • added check if ping is possible
  • fixed typo

Package Sidebar

Install

npm i net-toolkit.js

Weekly Downloads

3

Version

1.2.0

License

MIT

Unpacked Size

47.4 kB

Total Files

7

Last publish

Collaborators

  • gregorboxer-sudo