0.1.28 • Published 1 year ago

microtec-get-remote-time-windows v0.1.28

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

GetRemoteTimeWindows

Description

This function allows to get the data and the time of a remote windows machine. In the same step it is calculated the difference in milliseconds between the time of the remote machine and the local time. Internally - depending on the parameters - the "NetRemoteTOD" C++ function or the "net time" windows command line tool are used. If not absolutely necessary, "net time" should not be used, because it is not so precise than "NetRemoteTOD" and unlike "NetRemoteTOD" it does not observe time zones. Using the method "NetRemoteTOD" is more precise and secure.

Declaration

GetRemoteTimeWindows(remoteHost: string, credentials: { user: string, password?: string } = undefined, method = GetRemoteTimeWindowsMethod.NetRemoteTOD, netTimeRegex = '', netTimeFormat = ''): Promise<RemoteTimeDto>;

Parameters

  • remoteHost: The IP-address or hostname of the remote machine. Examples: '10.0.10.125', 'pc.domain.local'.
  • credentials: Optional. The credentials for the authentication to the remote machine.
  • method: Optional. The method to use to receive the time from the remote machine. Possible values are:
    • GetRemoteTimeWindowsMethod.NetRemoteTOD: use the "NetRemoteTOD" C++ function (default)
    • GetRemoteTimeWindowsMethod.NetTime: use the "net time" windows command line tool
    • GetRemoteTimeWindowsMethod.NetRemoteTODOnErrorNetTime: use the "NetRemoteTOD" C++ function. If it fails, try it again with the "net time" windows command line tool
  • netTimeRegex: Optional. Only has effect if the "net time" windows command line tool is used. The output of this windows command is language dependent. Define here the regex to get the date/time part (the date/time part has to be the first match). Example: Current time at .* is (.*).
  • netTimeFormat: Optional. Only has effect if the "net time" windows command line tool is used. The output of this windows command is language dependent. Without this parameter the library tries to automatically parse the date and time, but to be sure, it is better to define the format here. See https://momentjs.com/docs/#/parsing/string-format for the format specifications. Example for German: 'DD.MM.YYYY HH:mm:ss'. Example for English (US): 'M/D/YYYY h:mm:ss A'.

Return value

The function returns a Promise. On success the value of the Promise is an object of the type RemoteTimeDto.

The function can throw exceptions of the type Error.

RemoteTimeDto {
    remoteTime: Date;                    // Date and time of the remote machine
    remoteTimezone: number;              // Time zone in minutes of the remote machine (GMT+0 = 0, GMT+1 = 60, GMT+2 = 120, ...). Only available with method _NetRemoteTOD_.
    localTime: Date;                     // Date and time of the local machine
    localTimezone: number;               // Time zone in minutes of the local machine (GMT+0 = 0, GMT+1 = 60, GMT+2 = 120, ...). Only available with method _NetRemoteTOD_.
    difference: number;                  // The difference in milliseconds between the remote machine and the local machine (the difference is time zone independent)
    method: GetRemoteTimeWindowsMethod;  // The method used to receive the date and time. Can be GetRemoteTimeWindowsMethod.NetRemoteTOD or GetRemoteTimeWindowsMethod.NetTime
}

Usage

Install the node package:

npm install microtec-get-remote-time-windows

Import in CommonJS style:

const { GetRemoteTimeWindows } = require("microtec-get-remote-time-windows");

Import in ES6 module style:

import { GetRemoteTimeWindows } from "microtec-get-remote-time-windows";

Example code 1:

GetRemoteTimeWindows("10.0.10.125")
    .then(result => {
        console.log(result);
    })
    .catch(err => {
        console.error(err.message);
    });

Example code 2:

try {
    const result = await GetRemoteTimeWindows("10.0.10.125", { user: "username", password: "password" });
    console.log(result);
}
catch (err) {
    console.error(err.message);
}
0.1.26

1 year ago

0.1.27

1 year ago

0.1.28

1 year ago

0.1.22

2 years ago

0.1.23

2 years ago

0.1.24

2 years ago

0.1.25

2 years ago

0.1.21

2 years ago

0.1.20

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago