danielzzz / node-ping

a poor man's ping library (using udp scanning) for node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Misleading values in returned object when the cable is unplugged or the host doesn't exist

lucamarogna opened this issue · comments

commented

Writing these tests:

console.log( await ping.promise.probe('fakehostdoesntexist.com') );
// Manually unplug the cable...
console.log( await ping.promise.probe('google.com') );

both result in:

{
  host: 'unknown',
  alive: false,
  output: '',
  time: 'unknown',
  times: [],
  min: 'unknown',
  max: 'unknown',
  avg: 'unknown',
  stddev: 'unknown',
  packetLoss: 'unknown'
}

(the latter happen only when the network cable is unplugged)

I think it should have at least the host property setted to the actual host pinged. Not sure for other properties as ping implementation may vary depending on platforms (I'm on Ubuntu 18.04.3).

commented

Ok that's totally fine.

For me, it would be better to have the host value because I'm running several promises in parallel (Promise.all()) and I didn't know which has failed (e.g. "fakehostdoesntexist.com"), but I do catch your point.

Thank you for your response and explanation.

For your case, how about adding a key, say, userInputHost in the response object.

Therefore, we have around 3 keys talking about hosts but with subtle difference:

  • userInputHost: As title, host inputted from user
  • host: Host parsed from the system command
  • numeric_host: Host parsed, if possible, from the system command in a numeric format

Hopefully, it can address your issue

You can checkout this new implementation in the master branch on github.

commented

For your case, how about adding a key, say, userInputHost in the response object.

Therefore, we have around 3 keys talking about hosts but with subtle difference:

  • userInputHost: As title, host inputted from user
  • host: Host parsed from the system command
  • numeric_host: Host parsed, if possible, from the system command in a numeric format

Hopefully, it can address your issue

I don't find this commit in the latest npm version v0.4.0 . Could you please check it, thanks a lot.