2.0.7 • Published 4 years ago

@tulpep/foundit-remotecommand v2.0.7

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

FOUNDiT Remote Command Module

Module for execute remote commands.

Supported Operating Systems

  • Windows
  • Linux

How to Install it

npm i @tulpep/foundit-remotecommand

Available Methods

remoteCommand()

It allows you to execute commands in remote devices.

Parameters

function remoteCommand(fileToCopy, command, device, remoteWindows, username, password)

    fileToCopy: {
        remoteFolder: 'foundit' // the remote folder where the file will be copied.
        localfilePath: '/home/foundit/agent' // The path to the local file to be copied.
    }
    command: 'hostname' // command to execute
    device: 'PC-test' or '192.168.137.2' // specify the device to execute remote commands.
    remoteWindows: 'true' // true if the remote device is Windows.
    username: 'username' // specify the username to authenticate in remote device.
    password: 'Passw0rd' // specify the password to authenticate in remote device.

If fileToCopy parameter has value, the file copied will be executed with the command parameter, otherwise, if fileToCopy is undefined the command parameter will run directly on the console.

Example return for Windows

    {
        exitCode: 0,
        message:'Connecting to 192.168.137.2...\r\r\rStarting PSEXESVC service on 192.168.137.2...\r\r\rConnecting with PsExec service on 192.168.137.2...\r\r\rStarting hostname on 192.168.137.2...\r\r\r\r\nhostname exited on 192.168.137.2 with error code 0.'
        portRecheable: true
    }

Example return for Linux

    {   
        exitCode: 0,
        message: 'Lnx-Comp',
        portRecheable: true
    }

copyFileToRemoteDevice()

It allows you to copy a local file to a remote device.

Parameters

function copyFileToRemoteDevice(localfilePath, md5, device, remoteWindows, remoteFolder, username, password)

    localfilePath: '/home/foundit/agent.exe' // The path to the local file to be copied.
    md5: '9810784ce10b72a1ef2f50bc5fec59ba' // Optional md5 of the file to be copied.
    device: 'PC-test' or '192.168.137.2' // specify the device to execute remote commands.
    remoteWindows: 'true' // true if the remote device is Windows.
    remoteFolder: 'foundit' // the remote folder where the file will be copied.
    username: 'username' // specify the username to authenticate in remote device.
    password: 'Passw0rd' // specify the password to authenticate in remote device.

If the md5 parameter is undefined, this module will generate the MD5 of the file to be copied.

Example return for Windows

    {
        exitCode: 0,
        message:'File copied successfully' 
        finalPath: C:\\users\\foundit\\9810784ce10b72a1ef2f50bc5fec59ba.exe'
    }

Example return for Linux

    {
        exitCode: 0,
        message:'File copied successfully' 
        finalPath: /home/foundit/9810784ce10b72a1ef2f50bc5fec59ba.exe'
    }

How To Use it:

const remote = require('@tulpep/foundit-remotecommand')();

async function testCommandExecutor() {
    const response = await remote.remoteCommand(undefined, 'hostname', '192.168.137.2', true, 'jasg', 'PHE123');
    return response;
};

async function testCopyFile() {
    const response = await remote.copyFileToRemoteDevice('./package.json', undefined, '192.168.137.2', true, 'foundit', 'jasg', 'PHE123');
    return response;
};

const command = testCommandExecutor();
console.log('command');
console.log(command);
const copy = testCopyFile();
console.log('copy');
console.log(copy);

Dependencies

  • samba-client | License MIT: This library is a Node JS wrapper for smbclient. It allows you to access a SMB2 share as if you were using the native fs library.

  • @tulpep/foundit-cross | License MIT: This module to execute commands to the operating system and platform validate.

  • hasha | License MIT: Hashing made simple. Get the hash of a buffer/string/stream/file.

  • is-port-reachable | License MIT: Check if a local or remote port is reachable.

  • node-ssh | License MIT: Node-SSH is an extremely lightweight Promise wrapper for ssh2, Period.

  • winexe | License MIT: Wrapper around the winexe and psexec.

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago