Una sencilla herramienta de ping. Admite protocolo TCP/UDP/ICMP.
Pingus puede...
Enviar solicitud de eco ICMP y traceroute ttl.
Envíe ping, escanee a puertos TCP/UDP y capture pancartas.
Envíe paquetes mágicos (Wake on LAN) mediante ping UDP.
pingus.Ping'ready''result''error'ping.send()pingus.PingTCP Extiende: pingus.Pingnew PingTCP(options)pingtcp.send()pingtcp.scan()pingus.PingUDP Extiende: pingus.Pingnew PingUDP(options)pingudp.send()pingudp.scan()pingus.PingICMP Extiende: pingus.Pingnew PingICMP(options)pingicmp.send()pingicmp.traceroute()Callback o Promise ( async/await )pingus.tcp(options[, callback])pingus.tcpscan(options[, callback])pingus.udp(options[, callback])pingus.udpscan(options[, callback])pingus.wol(mac, options[, callback])pingus.icmp(options[, callback])pingus.traceroute(options[, callback]) npm i pingus
Si se produce un error durante la instalación, puede deberse a un error de instalación de los siguientes paquetes.
Se puede solucionar instalando el compilador GCC.
En Ubuntu:
sudo apt-get install -y build-essentialEn Windows:
Instale Visual Studio incluido el Desktop development with C++ .
// TCP Ping to localhost:22
import pingus from 'pingus' ; // ESM, Typescript
const pingus = require ( 'pingus' ) ; // CJS
pingus . tcp ( { host : 'localhost' , port : 22 } ) . then ( console . log ) ; // Result
{
type : 'ping/tcp' ,
status : 'open' ,
host : 'localhost' ,
ip : IP { label : '127.0.0.1' } ,
ips : [ IP { label : '127.0.0.1' } ] ,
time : 2 ,
port : 22 ,
name : 'ssh' ,
banner : 'SSH-2.0-OpenSSH_8.9p1 Ubuntu-3'
toPrimitiveJSON : [ Function ( anonymous ) ]
}pingus.Ping pingus.Ping es EventEmitter con los siguientes eventos:
'ready'result <Object> Emitido cuando está listo (Resolver DNS, Filtrar IP de Bogon) para enviar ping después de llamar ping.send() .
import pingus from 'pingus' ;
const ping = new pingus . PingTCP ( {
host : 'example.com' ,
} ) ;
ping . on ( 'ready' , ( result ) => {
const data = result . toPrimitiveJSON ( ) ;
console . log ( 'pingttarget:t' , data . host ) ;
console . log ( 'tips:t' , data . ips ) ;
} ) ;
ping . send ( ) ; ping target: example.com
ips: [ '93.184.215.14', '2606:2800:021f:cb07:6820:80da:af6b:8b2c' ]
'result'result <Object>Resultado de los datos de ping.
import pingus from 'pingus' ;
const ping = new pingus . PingTCP ( {
host : 'example.com' ,
} ) ;
ping . on ( 'result' , ( result ) => {
const data = result . toPrimitiveJSON ( ) ;
console . log ( result ) ;
} ) ;
ping . send ( ) ; {
type : 'ping/tcp' ,
status : 'open' ,
host : 'example.com' ,
ip : '93.184.215.14' ,
ips : [ '93.184.215.14' , '2606:2800:021f:cb07:6820:80da:af6b:8b2c' ] ,
time : 134 ,
port : 80 ,
name : 'http' ,
banner : ''
}'error'<Error>result <Object> Emitido cuando ocurre un error. result tiene la última declaración antes de que ocurra el error y el código de error.
ping.send()Enviar ping. Vea algunos ejemplos en Uso
pingus.PingTCP Extiende: pingus.Ping Clase para ping TCP.
pingus.PingTCP es el tipo de pingus.Ping
new PingTCP(options)options <Object>host <string> Establece el nombre de host de destino (dominio) o la dirección IP.port <number> Establece el puerto de destino cuando usas pingtcp.send() . Predeterminado: 80ports <Array> | <string> Establece los puertos de destino cuando usas pingtcp.scan() . Utilice una matriz de números de puerto o cadenas de consulta. Ver ejemplo.timeout <number> número> Establecer tiempo de espera. Predeterminado: 2000resolveDNS <boolean> Resuelve registros DNS A y AAAA cuando host es la dirección de dominio. Predeterminado: truednsServer <string> Configure el servidor DNS para resolver registros DNS.filterBogon <boolean> Filtra la dirección IP de bogon en host . Predeterminado: true options.ports ports: [ 21 , 22 , 80 , 443 ] ; // Scan port 21, 22, 80, 443 ports: '21,22,80,443' ; // Scan port 21, 22, 80, 443 ports: '21-80' ; // Scan ports in range 21 to 80 (21, 22, 23 ... 78, 79, 80) ports: '21-25,80,443' ; // Scan ports in range 21 to 25 and 80, 443 ports: '@' ; // Scan most used 1024 ports in protocol ports: '*' ; // Scan all ports (1 to 65535)pingtcp.send() Ver ping.send() . Algunos de los ejemplos en Uso.
pingtcp.scan() Escanee puertos usando ping TCP. Devuelve resultado en Evento: 'result' . Vea algunos ejemplos en Uso.
pingus.PingUDP Extiende: pingus.Ping Clase para ping UDP.
pingus.PingUDP es el tipo de pingus.Ping
new PingUDP(options)options <Object>host <string> Establece el nombre de host de destino (dominio) o la dirección IP.port <number> Establece el puerto de destino cuando usas pingudp.send() . Predeterminado: 68ports <Array> | <string> Establece los puertos de destino cuando usas pingudp.scan() . Utilice una matriz de números de puerto o cadenas de consulta. Igual que PingTCP. Ver ejemplo.buffer <Buffer> Establece el buffer cuando se envía en el socket de ping UDP conectado.body <string> Establece el cuerpo cuando se envía en el socket de ping UDP conectado. Se ignora cuando se configuran las opciones buffer .bytes <number> Establece una longitud de bytes aleatoria cuando se envía en un socket de ping UDP conectado. Se ignora cuando se configuran las opciones body . Predeterminado: 32timeout <number> número> Establecer tiempo de espera. Predeterminado: 2000resolveDNS <boolean> Resuelve registros DNS A y AAAA cuando host es la dirección de dominio. Predeterminado: truednsServer <string> Configure el servidor DNS para resolver registros DNS.filterBogon <boolean> Filtra la dirección IP de bogon en host . Predeterminado: truepingudp.send() Ver ping.send() . Algunos de los ejemplos en Uso.
pingudp.scan() Similar con pingtcp.scan() .
Escanee puertos usando ping UDP. Devolver resultado en Evento: 'result' . Vea algunos ejemplos en Uso.
pingus.PingICMP Extiende: pingus.Ping Clase para ping ICMP.
pingus.PingICMP es el tipo de pingus.Ping
new PingICMP(options)options <Object>host <string> Establece el nombre de host de destino (dominio) o la dirección IP.ttl <number> Establecer ttl. Predeterminado: 128ttln <number> Establece el ttl de inicio cuando se utiliza pingicmp.traceroute() . Predeterminado: 1ttlx <number> Establece el ttl máximo cuando se usa pingicmp.traceroute() . Predeterminado: 64timeout <number> número> Establecer tiempo de espera. Predeterminado: 2000timeoutx <number> Establece la pila de tiempo de espera máxima cuando se usa pingicmp.traceroute() . Predeterminado: 8resolveDNS <boolean> Resuelve registros DNS A y AAAA cuando host es la dirección de dominio. Predeterminado: truednsServer <string> Configure el servidor DNS para resolver registros DNS.filterBogon <boolean> Filtra la dirección IP de bogon en host . Predeterminado: truepingicmp.send() Ver ping.send() . Algunos de los ejemplos en Uso.
pingicmp.traceroute()Ejecute traceroute. Algunos de los ejemplos en Uso.
Callback o Promise ( async/await )Vea ejemplos en Enviar estilos de ping.
pingus.tcp(options[, callback])Enviar ping TCP.
pingus.tcpscan(options[, callback])Escanee puertos usando ping TCP.
pingus.udp(options[, callback])Enviar ping UDP.
pingus.udpscan(options[, callback])Escanee puertos usando ping UDP.
pingus.wol(mac, options[, callback])mac <string> Establecer la dirección MAC de destino.options <Object> Igual que las opciones del new PingUDP(options)Envíe el ping UDP del paquete mágico para utilizar la función WOL.
pingus.icmp(options[, callback])Enviar ping ICMP.
pingus.traceroute(options[, callback])Ejecute traceroute.
ESM (mecanografiado)
import pingus from 'pingus' ;CJS
const pingus = require ( 'pingus' ) ; Class extiende EventEmitter // TCP ping to localhost:80
new pingus . PingTCP ( { host : 'localhost' } )
. on ( 'result' , ( result ) => {
console . log ( result . toPrimitiveJSON ( ) ) ;
} )
. on ( 'error' , ( err , result ) => {
throw err ;
} )
. send ( ) ;Callback // TCP ping to localhost:80
pingus . tcp ( { host : 'localhost' } , ( err , result ) => {
if ( err ) {
throw err ;
}
console . log ( result ) ;
} ) ;Promise // TCP ping to localhost:80
pingus
. tcp ( { host : 'localhost' } )
. then ( ( result ) => {
console . log ( result . toPrimitiveJSON ( ) ) ;
} )
. catch ( ( err ) => {
throw err ;
} ) ;async/await // TCP ping to localhost:80
const result = await pingus . tcp ( { host : 'localhost' } ) ;
console . log ( result . toPrimitiveJSON ( ) ) ; {
type : 'ping/tcp' ,
status : 'open' ,
host : 'localhost' ,
ip : '127.0.0.1' ,
ips : [ '127.0.0.1' ] ,
time : 2 ,
port : 80 ,
name : 'http' ,
banner : ''
} // TCP ping to localhost:22
new pingus . PingTCP ( { host : 'localhost' , port : 22 } )
. on ( 'result' , ( result ) => {
console . log ( result . toPrimitiveJSON ( ) ) ;
} )
. on ( 'error' , ( err , result ) => {
throw err ;
} )
. send ( ) ; {
type : 'ping/tcp' ,
status : 'open' ,
host : 'localhost' ,
ip : '127.0.0.1' ,
ips : [ '127.0.0.1' ] ,
time : 2 ,
port : 22 ,
name : 'ssh' ,
banner : 'SSH-2.0-OpenSSH_8.9p1 Ubuntu-3'
} // TCP ping scan to localhost
new pingus . PingTCP ( {
host : 'localhost' ,
ports : [ 21 , 22 , 80 , 443 , 3306 , 8080 ] ,
} )
. on ( 'result' , ( result ) => {
console . log ( result . toPrimitiveJSON ( ) ) ;
} )
. on ( 'error' , ( err , result ) => {
throw err ;
} )
. scan ( ) ; {
type : 'ping/tcp/scan' ,
status : 'finish' ,
host : 'localhost' ,
ip : '127.0.0.1' ,
ips : [ '127.0.0.1' ] ,
time : 2009 ,
port : 80 ,
name : 'http' ,
banner : '' ,
ports : [ 21 , 22 , 80 , 443 , 3306 , 8080 ] ,
statuses : {
open : [ 22 , 80 , 8080 ] ,
reset : [ ] ,
close : [ 21 , 443 , 3306 ] ,
filtered : [ ] ,
error : [ ]
} ,
names : {
'21' : 'ftp' ,
'22' : 'ssh' ,
'80' : 'http' ,
'443' : 'https' ,
'3306' : 'mysql' ,
'8080' : 'http-alt'
} ,
banners : { '22' : 'SSH-2.0-OpenSSH_8.9p1 Ubuntu-3' } ,
errors : { }
} // UDP ping to localhost:19132
new pingus . PingUDP ( { host : 'localhost' , port : 19132 } )
. on ( 'result' , ( result ) => {
console . log ( result . toPrimitiveJSON ( ) ) ;
} )
. on ( 'error' , ( err , result ) => {
throw err ;
} )
. send ( ) ; {
type : 'ping/udp' ,
status : 'close' ,
host : 'localhost' ,
ip : '127.0.0.1' ,
ips : [ '127.0.0.1' ] ,
time : 2 ,
port : 19132 ,
name : 'minecraft-be'
} // UDP ping scan to localhost
new pingus . PingUDP ( {
host : 'localhost' ,
ports : [ 67 , 68 , 161 , 162 , 445 ] ,
} )
. on ( 'result' , ( result ) => {
console . log ( result . toPrimitiveJSON ( ) ) ;
} )
. on ( 'error' , ( err , result ) => {
throw err ;
} )
. scan ( ) ; {
error : undefined ,
type : 'ping/udp/scan' ,
status : 'finish' ,
host : 'localhost' ,
ip : '127.0.0.1' ,
ips : [ '127.0.0.1' ] ,
time : 2003 ,
ports : [ 67 , 68 , 161 , 162 , 445 ] ,
statuses : {
open : [ 68 ] ,
reset : [ ] ,
close : [ 67 , 161 , 162 , 445 ] ,
filtered : [ ] ,
error : [ ]
} ,
names : {
'67' : 'bootps' ,
'68' : 'bootpc' ,
'161' : 'snmp' ,
'162' : 'snmptrap' ,
'445' : 'microsoft-ds'
} ,
banners : { } ,
errors : { }
} // Send magic packet using UDP ping to 00-00-00-00-00-00
pingus
. wol ( '00-00-00-00-00-00' )
. then ( ( result ) => {
console . log ( result . toPrimitiveJSON ( ) ) ;
} )
. catch ( ( error ) => {
throw error ;
} ) ; {
type : 'ping/udp' ,
status : 'open' ,
host : '255.255.255.255' ,
ip : '255.255.255.255' ,
ips : [ '255.255.255.255' ] ,
time : 2 ,
port : 9 ,
name : 'discard'
} // ICMP ping to example.com
new pingus . PingICMP ( { host : 'example.com' } )
. on ( 'result' , ( result ) => {
console . log ( result . toPrimitiveJSON ( ) ) ;
} )
. on ( 'error' , ( err , result ) => {
throw err ;
} )
. send ( ) ; {
type : 'ping/icmp' ,
status : 'reply' ,
host : 'example.com' ,
ip : '93.184.215.14' ,
ips : [ '93.184.215.14' , '2606:2800:021f:cb07:6820:80da:af6b:8b2c' ] ,
time : 130 ,
ttl : 128 ,
bytes : 32 ,
reply : {
source : '93.184.216.34' ,
type : 0 ,
code : 0 ,
typestr : 'ECHO_REPLY' ,
codestr : 'NO_CODE' ,
body : '767284c4'
}
} // ICMP ping to example.com using ttl = 10
new pingus . PingICMP ( { host : 'example.com' , ttl : 10 } )
. on ( 'result' , ( result ) => {
console . log ( result . toPrimitiveJSON ( ) ) ;
} )
. on ( 'error' , ( err , result ) => {
throw err ;
} )
. send ( ) ; {
type : 'ping/icmp' ,
status : 'exception' ,
host : 'example.com' ,
ip : '93.184.215.14' ,
ips : [ '93.184.215.14' , '2606:2800:021f:cb07:6820:80da:af6b:8b2c' ] ,
time : 133 ,
ttl : 10 ,
bytes : 32 ,
reply : {
source : '152.195.76.133' ,
type : 11 ,
code : 0 ,
typestr : 'TIME_EXCEEDED' ,
codestr : 'NO_CODE' ,
body : ']8X"bx00CQx00x00x00x00'
}
} // Traceroute to example.com
new pingus . PingICMP ( { host : 'example.com' , timeout : 500 } )
. on ( 'result' , ( result ) => {
console . log ( result . toPrimitiveJSON ( ) ) ;
} )
. on ( 'error' , ( err , result ) => {
throw err ;
} )
. traceroute ( ) ; {
type : 'ping/icmp/traceroute' ,
status : 'finish' ,
host : 'example.com' ,
ip : '93.184.215.14' ,
ips : [ '93.184.215.14' , '2606:2800:021f:cb07:6820:80da:af6b:8b2c' ] ,
time : 7614 ,
ttl : 128 ,
bytes : 32 ,
hops : [
{
status : 'time_exceeded' ,
ip : '172.19.80.1' ,
ttl : 1 ,
rtt : { min : 0 , max : 1 , avg : 1 }
} ,
{
status : 'time_exceeded' ,
ip : '172.30.1.254' ,
ttl : 2 ,
rtt : { min : 0 , max : 1 , avg : 1 }
} ,
{
status : 'timeout' ,
ip : null ,
ttl : 3 ,
rtt : { min : 2001 , max : 2002 , avg : 2002 }
} ,
{
status : 'time_exceeded' ,
ip : '112.188.59.77' ,
ttl : 4 ,
rtt : { min : 2 , max : 3 , avg : 3 }
} ,
{
status : 'time_exceeded' ,
ip : '112.188.53.13' ,
ttl : 5 ,
rtt : { min : 1 , max : 2 , avg : 2 }
} ,
{
status : 'time_exceeded' ,
ip : '112.174.47.177' ,
ttl : 6 ,
rtt : { min : 7 , max : 8 , avg : 8 }
} ,
{
status : 'time_exceeded' ,
ip : '112.174.91.130' ,
ttl : 7 ,
rtt : { min : 7 , max : 8 , avg : 8 }
} ,
{
status : 'time_exceeded' ,
ip : '112.174.87.102' ,
ttl : 8 ,
rtt : { min : 129 , max : 130 , avg : 130 }
} ,
{
status : 'time_exceeded' ,
ip : '206.72.210.112' ,
ttl : 9 ,
rtt : { min : 127 , max : 128 , avg : 128 }
} ,
{
status : 'time_exceeded' ,
ip : '152.195.76.151' ,
ttl : 10 ,
rtt : { min : 132 , max : 134 , avg : 133 }
} ,
{
status : 'reply' ,
ip : '93.184.215.14' ,
ttl : 11 ,
rtt : { min : 126 , max : 126 , avg : 126 }
}
]
}