tomas / network

The missing network utilities in Node.js.
111 stars 49 forks source link

Re process for Windows #19

Closed TotallyInformation closed 7 years ago

TotallyInformation commented 7 years ago

https://www.npmjs.com/package/default-network uses calls to WMI and https://www.npmjs.com/package/ms-wmic is a WMI wrapper so it should be possible to use those to create a Windows capability.

tomas commented 7 years ago

I'm not sure what you mean. What would those modules be useful for?

TotallyInformation commented 7 years ago

The first one shows you what calls you need to do to query the windows management interface for the networking information under Windows. The second is a helper module for calling the Windows management interface though all it really does is spawn out to the wmic executable.

You asked for information on the readme file about how to get the network information on the Windows platform and wmic is how you do it.

shaynem commented 7 years ago

Here is a batch script that gets the gateway IP for windows - Might be helpful as per your readme

read_gateway = spawn('cmd', ['\/c', fs.realpathSync('.') + '\lib\bin\windows\gateway.bat']);

@echo off SETLOCAL ENABLEDELAYEDEXPANSION @For /f "tokens=3" %% in ( 'route.exe print ^|findstr "\<0.0.0.0>"' ) Do @Set "DefaultGateway=%%" echo %DefaultGateway% ENDLOCAL

TotallyInformation commented 7 years ago

the problem with scripts like that is that they often fail if using non-English versions of Windows. Using the WMI API is preferred.

tomas commented 7 years ago

This should probably work now, without the need of any scripts. Can you guys try and see if it works?

TotallyInformation commented 7 years ago

Well good news and bad news :}

Good news is that the external lookup & interface list seem to work fine.

For the internal ip lookup and active interface, not so good. On my PC, it returns a VMware virtual adapter and not the actually active interface - albeit that is via an external USB dock just now so my setup is far from normal as I have 5 active interfaces and 3 disconnected ones.

Because it finds the wrong default interface, the gateway lookup also fails since there is no gateway on that interface - so I'm not sure whether that is working or not.

However, a quick look at the win32 code would seem to be correct so I will blame my odd machine setup and WMIC's failure rather than your code.

Nice work, thanks.