Amuject / Pingus

A simple network ping tool in nodejs. Supports TCP / UDP / ICMP protocol.
https://www.npmjs.com/package/pingus
MIT License
19 stars 3 forks source link

ENOTFOUND when using with internal hostname #1

Closed davistran86 closed 1 year ago

davistran86 commented 1 year ago

Hi author, thanks for this awesome package. Can you please help on issue with ENOTFOUND when using with my internal hostname ? I have already specified a dns server but it's not working. I'm sure the hostname is resolved in terminal. my code:

import pingus from "pingus";

const ping = new pingus.PingICMP({
  host: "my.myserver.abc.local",
  ttl: 128,
  bytes: 32,
  dnsServer: "192.168.30.222",
  resolveDNS: true,
}) as any;
ping.on("ready", (result) => {
  console.log("ping\ttarget:\t", result.host);
  console.log("\tips:\t", result.ips);
});
ping.send();
davistran86 commented 1 year ago

I don't know why but importing node:dns make this works:

import * as dns from "dns";
import pingus from "pingus";

const ping = new pingus.PingICMP({
  host: "my.myserver.abc.local",
  ttl: 128,
  bytes: 32,
  dnsServer: "192.168.30.222",
  resolveDNS: true,
}) as any;
ping.on("ready", (result) => {
  console.log("ping\ttarget:\t", result.host);
  console.log("\tips:\t", result.ips);
});
ping.send();
wnynya commented 1 year ago

Sorry. I can't reproduce error like you. I don't have an internal dns server. So I tested some of known dns servers(1.1.1.1, 8.8.8.8, 8.26.56.26, 64.6.64.6). but it worked (all dns servers send me an different ips).

import pingus from 'pingus';

const ping = new pingus.PingICMP({
  host: 'google.com',
  ttl: 128,
  bytes: 32,
  dnsServer: '1.1.1.1', // change to 8.8.8.8, 8.26.56.26, 64.6.64.6
  resolveDNS: true,
});
ping.on('result', (result) => {
  console.log('ping\ttarget:\t', result.host);
  console.log('\tips:\t', result.ips);
});
ping.send();

Additionally README has an error. you need to fix ping.on("ready" ... to ping.on("result" ...