@network-utils/tcp-ping
Version:
A simple TCP ping util, written in Typescript, to test the reachability and latency of a host.
97 lines (96 loc) • 2.22 kB
TypeScript
/**
* Ping Options
*/
export interface IPingOptions {
/**
* The IP address of the device being pinged
*/
address: string;
/**
* The port to ping
*/
port: number;
/**
* The number of times
* `tcp-probe#ping` will attempt to connect to `address`
*/
attempts: number;
/**
* The time whichafter each TCP socket will timeout
*/
timeout: number;
}
/**
* The result of ping attempt that failed
*/
export interface IPingError {
/**
* The number of the attempt
*/
attempt: number;
/**
* The error that occured
*/
error: Error;
}
/**
* The results of a ping attempt
*/
export interface IPingResult {
/**
* The options that were used for this ping
*/
options: IPingOptions;
/**
* The average latency of this ping
*/
averageLatency: number;
/**
* The latency of the fastest attempt
*/
minimumLatency: number;
/**
* The latency of the slowest attempt
*/
maximumLatency: number;
/**
* All the ping attempts that failed
*/
errors: IPingError[];
}
/**
* The result of a connection attempt
*/
export interface IConnectionAttempt {
/**
* The number of this attempt
*/
attemptNumber: number;
/**
* The result of the connection
*/
result: {
/**
* The time it took to connect (e.i. the latency of the connection)
*/
time?: number;
/**
* The `Error` that caused the connection to fail
*/
error?: Error;
};
}
/**
* Pings the given device and report the statistics
* in the form of an `IPingResult` object
* @param options The `IPingOptions` object
*/
export declare function ping(options?: Partial<IPingOptions>, progress?: (progress: number, total: number) => void): Promise<IPingResult>;
/**
* Makes one attempt to reach the host and returns
* a `boolean` indicating whether or not it was successful.
* @param port The port to probe
* @param address The address to probe
* @param timeout The timeout of the probe
*/
export declare function probe(port: number, address?: string, timeout?: number): Promise<boolean>;