silverwind / default-gateway

Get the default network gateway, cross-platform.
86 stars 19 forks source link

Select the gateway with the lowest metric on Windows #17

Closed eycorsican closed 5 years ago

eycorsican commented 5 years ago

May fix #15

silverwind commented 5 years ago

Some lint errors:


win32.js
  15:3   error  Unexpected var, use let or const instead  no-var
  17:56  error  Strings must use doublequote              quotes
  17:74  error  Strings must use doublequote              quotes
silverwind commented 5 years ago

Otherwise, approach looks good.

eycorsican commented 5 years ago

Lint errors fixed.

It's worth to note that this PR fixes the case where there are multiple default routes to their own gateways, but the current implementation still fails when there are multiple default routes with different metrics to the SAME gateway, though it a rare case.

silverwind commented 5 years ago

Merged this in https://github.com/silverwind/default-gateway/commit/771706d18779d803eeab960c35fd17cd9046360b and did a rework of the parsing in https://github.com/silverwind/default-gateway/commit/1b6d124ab9811438db1d670fcdb30445814634ab.

Your version did not support multiple IP versions which I've added. Also, it seems the final metric seen in netstat -nr is the sum of GatewayCostMetric and IPConnectionMetric, so I added that as well.

Maybe you can confirm that current master branch works for you.

eycorsican commented 5 years ago

master works well for me :)

silverwind commented 5 years ago

Thanks, released in default-gateway@5.0.3.