Net

Net

Source:

This module provides useful WSH (Windows Script Host) functions that handle network on Windows.

Requires

Namespaces

SMB

Methods

(static) enablesDHCP(macAddress, optionsopt) → {boolean}

Source:

Checks if the network adapter has DHCP enabled.

Example
var net = Wsh.Net; // Shorthand

net.enablesDHCP('XX:XX:XX:XX:XX:XX'); // Returns: true
Parameters:
Name Type Attributes Description
macAddress string

The adapter MACAddress to check.

options object <optional>

See Wsh.Net.getAdaptersPropsObjs

Returns:
  • If DHCP enabling, returns true.
Type
boolean

(static) exportWinFirewallSettings(destPath, optionsopt) → {object|string}

Source:

[Requires admin rights] Exports the binary file of Windows firewall settings.

Example
var net = Wsh.Net; // Shorthand

net.exportWinFirewallSettings('D:\\backup.wfw');
Parameters:
Name Type Attributes Description
destPath string

Recommend the extension .wfw

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
isDryRun boolean <optional>
false

No execute, returns the string of command.

runsAdmin boolean | undefined <optional>
true

true: as Admin, false: as User

Returns:
Type
object | string

(static) exportWinFirewallSettings(srcPath, optionsopt) → {object|string}

Source:

[Requires admin rights] Import file(binary) of Windows firewall settings.

Example
var net = Wsh.Net; // Shorthand

net.importWinFirewallSettings('D:\\backup.wfw');
Parameters:
Name Type Attributes Description
srcPath string
options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
runsAdmin boolean | undefined <optional>
true

true: as Admin, false: as User

isDryRun boolean <optional>
false

No execute, returns the string of command.

Returns:
Type
object | string

(static) getAdaptersConfsObjs(macAddressopt, optionsopt) → {Array.<object>}

Source:

Gets an Array of the network adapter configurations.

Example
var net = Wsh.Net; // Shorthand

var adapterConfs = net.getAdaptersConfsObjs();
console.dir(adapterConfs);
// Outputs: [
// {
//   ArpAlwaysSourceRoute: null,
//   ArpUseEtherSNAP: null,
//   Caption: "[00000014] Intel(R) 123456V Gigabit Network Connection",
//   DatabasePath: null,
//   DeadGWDetectEnabled: null,
//   DefaultIPGateway: "11.22.33.44",
//   DefaultTOS: null,
//   DefaultTTL: null,
//   Description: "Intel(R) 123456V Gigabit Network Connection",
//   DHCPEnabled: true,
//   DHCPLeaseExpires: "20161115082325.000000+540",
//   DHCPLeaseObtained: "20161108082325.000000+540",
//   DHCPServer: "11.22.33.44",
//   DNSDomain: "mypc.local",
//   DNSDomainSuffixSearchOrder: "mypc.local",
//   DNSEnabledForWINSResolution: false,
//   DNSHostName: "MYPC123456"
//   DNSServerSearchOrder: ["11.22.33.44", "11.22.33.55"],
//   DomainDNSRegistrationEnabled: false,
//   ForwardBufferMemory: null,
//   FullDNSRegistrationEnabled: true,
//   GatewayCostMetric: 0,
//   IGMPLevel: null,
//   Index: 14,
//   InterfaceIndex: 14,
//   IPAddress: ["11.22.33.44", "ab12::cd23:ef45:gh67:ij89"],
//   IPConnectionMetric: 10,
//   IPEnabled: true,
//   IPFilterSecurityEnabled: false,
//   IPPortSecurityEnabled: null,
//   IPSecPermitIPProtocols: null,
//   IPSecPermitTCPPorts: null,
//   IPSecPermitUDPPorts: null,
//   IPSubnet: "255.255.255.0,64",
//   IPUseZeroBroadcast: null,
//   IPXAddress: null,
//   IPXEnabled: null,
//   IPXFrameType: null,
//   IPXMediaType: null,
//   IPXNetworkNumber: null,
//   IPXVirtualNetNumber: null,
//   KeepAliveInterval: null,
//   KeepAliveTime: null,
//   MACAddress: "XX:XX:XX:XX:XX:XX",
//   MTU: null,
//   NumForwardPackets: null,
//   PMTUBHDetectEnabled: null,
//   PMTUDiscoveryEnabled: null,
//   ServiceName: "xxxxxx64",
//   SettingID: "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}",
//   TcpipNetbiosOptions: null,
//   TcpMaxConnectRetransmissions: null,
//   TcpMaxDataRetransmissions: null,
//   TcpNumConnections: null,
//   TcpUseRFC1122UrgentPointer: null,
//   TcpWindowSize: 65432,
//   WINSEnableLMHostsLookup: null,
//   WINSHostLookupFile: null,
//   WINSPrimaryServer: "11.22.33.44",
//   WINSScopeID: null,
//   WINSSecondaryServer: "11.22.33.44"
// }, {
//    ...
//    ..
// }]
Parameters:
Name Type Attributes Description
macAddress string <optional>

If empty, gets all adapters.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
excludesVirtual boolean <optional>
true
excludesWireless boolean <optional>
false
Returns:
  • An Array of the network adapters configurations objects.
Type
Array.<object>

(static) getAdaptersConfsSWbemObjs(macAddressopt, optionsopt) → {Array.<sWbemObjectSet>}

Source:

Gets an Array of Enumerated-SWbemObjectSet of network adapter configurations on the Windows. See Win32 Network Adapter Configuration Properties.

Example
var net = Wsh.Net; // Shorthand

var adapterConfs = net.getAdaptersConfsSWbemObjs();
// Returns: An Array of Win32 Network Adapter Configuration Properties.
Parameters:
Name Type Attributes Description
macAddress string <optional>

If empty, gets all adapters.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
excludesVirtual boolean <optional>
true
excludesWireless boolean <optional>
false
Returns:
Type
Array.<sWbemObjectSet>

(static) getAdaptersPropsObjs(macAddressopt, optionsopt) → {Array.<object>}

Source:

Gets an Array of objects of network adapteres on the Windows.

Example
var net = Wsh.Net; // Shorthand

var adapters = net.getAdaptersPropsObjs();
console.dir(adapters);
// Outputs: [
// {
//   AdapterType: "イーサネット 802.3",
//   AdapterTypeId: 0,
//   AutoSense: null,
//   Availability: 3,
//   Caption: "[00000001] Intel(R) Ethernet Connection (7) I999-V",
//   ConfigManagerErrorCode: 0,
//   ConfigManagerUserConfig: false,
//   CreationClassName: "Win32_NetworkAdapter",
//   Description: "Intel(R) Ethernet Connection (7) I999-V",
//   DeviceID: "1",
//   ErrorCleared: null,
//   ErrorDescription: null,
//   GUID: "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}",
//   Index: 1,
//   InstallDate: null,
//   Installed: true,
//   InterfaceIndex: 11,
//   LastErrorCode: null,
//   MACAddress: "XX:XX:XX:XX:XX:XX",
//   Manufacturer: "Intel Corporation",
//   MaxNumberControlled: 0,
//   MaxSpeed: null,
//   Name: "Intel(R) Ethernet Connection (7) I999-V",
//   NetConnectionID: "イーサネット",
//   NetConnectionStatus: 2,
//   NetEnabled: true,
//   NetworkAddresses: null,
//   PermanentAddress: null,
//   PhysicalAdapter: true,
//   PNPDeviceID: "PCI\XXX_111X&XXX_1111&...",
//   PowerManagementCapabilities: null,
//   PowerManagementSupported: false,
//   ProductName: "Intel(R) Ethernet Connection (7) I999-V",
//   ServiceName: "xxxxxx64",
//   Speed: null,
//   Status: null,
//   StatusInfo: null,
//   SystemCreationClassName: "Win32_ComputerSystem",
//   SystemName: "MYPC123456"
//   TimeOfLastReset: "20161108082314.125599+540"
// }, {
//    ...
//    ..
// }]
Parameters:
Name Type Attributes Description
macAddress string <optional>

If empty, gets all adapters.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
excludesVirtual boolean <optional>
true
excludesWireless boolean <optional>
false
isConnecting boolean <optional>
false
Returns:
  • An Array of the network adapters properties objects.
Type
Array.<object>

(static) getAdaptersPropsSWbemObjs(macAddressopt, optionsopt) → {Array.<sWbemObjectSet>}

Source:

Gets an Array of Enumerated-SWbemObjectSet of network adapteres on the Windows. See Win32_NetworkAdapter class.

Example
var net = Wsh.Net; // Shorthand

var adapters = net.getAdaptersPropsSWbemObjs();
// Returns: An Array of Win32_NetworkAdapter class.
Parameters:
Name Type Attributes Description
macAddress string <optional>

If empty, gets all adapters.

options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
excludesVirtual boolean <optional>
true
excludesWireless boolean <optional>
false
isConnecting boolean <optional>
false
Returns:
Type
Array.<sWbemObjectSet>

(static) getDefaultGateways(macAddressopt, optionsopt) → {Array.<string>}

Source:

Gets the IP address of default gateway set in adapters.

Example
var net = Wsh.Net; // Shorthand

net.getDefaultGateways('XX:XX:XX:XX:XX:XX'); // Returns: ['11.22.33.44']
Parameters:
Name Type Attributes Description
macAddress string <optional>

If empty, gets all adapters.

options object <optional>

See Wsh.Net.getAdaptersConfsObjs

Returns:
  • An Array of the default gateway IP addresses.
Type
Array.<string>

(static) getDnsIPsSetInAdapters(macAddressopt, optionsopt) → {Array.<string>}

Source:

Gets the IP addresses of DNS set in adapters.

Example
var net = Wsh.Net; // Shorthand

net.getDnsIPsSetInAdapters('XX:XX:XX:XX:XX:XX'); // Returns: ['11.22.33.44']
Parameters:
Name Type Attributes Description
macAddress string <optional>

If empty, gets all adapters.

options object <optional>

See Wsh.Net.getAdaptersPropsObjs

Returns:
  • [0]:Primary DNS Server Address [1]:Secondary-
Type
Array.<string>

(static) getIpSetInAdapters(macAddressopt, optionsopt) → {Array.<string>}

Source:

Gets the IP address set in adapters.

Example
var net = Wsh.Net; // Shorthand

net.getIpSetInAdapters('XX:XX:XX:XX:XX:XX'); // Returns: ['11.22.33.44']
Parameters:
Name Type Attributes Description
macAddress string <optional>

If empty, gets all adapters.

options object <optional>

other options, See Wsh.Net.getAdaptersConfsObjs.

Properties
Name Type Attributes Default Description
ipVer string <optional>
'IPv4'

IPv4 or IPv6.

Returns:
  • The Array of the network adapters IP addresses.
Type
Array.<string>

(static) respondsHost(hostopt) → {boolean}

Source:

Checks if the host responds to ping.

Example
var net = Wsh.Net; // Shorthand

net.respondsHost('127.0.0.1'); // Returns: true
Parameters:
Name Type Attributes Description
host string <optional>

The host address to check.

Returns:
Type
boolean

(static) setDnsServers(netName, dns1opt, dns2opt, optionsopt) → {void|string}

Source:

Sets DNS addresses. Must closed the Windows network config window.

Example
var net = Wsh.Net; // Shorthand

net.setDnsServers('Ethernet 1', '11.22.33.1', '11.22.33.2');
Parameters:
Name Type Attributes Default Description
netName string

The NetConnectionID of the network adapter.

dns1 string <optional>

If empty, enables DHCP.

dns2 string <optional>
''
options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
runsAdmin boolean | undefined <optional>

true: as Admin, false: as User

isDryRun boolean <optional>
false

No execute, returns the string of command.

Returns:
  • If options.isDryRun is true, returns string.
Type
void | string

(static) setDnsServersWithWMI(netadpIndex, dnsAddsopt) → {boolean}

Source:

Sets the DNS server with WMI (Windows Management Instrumentation. WBEM for Windows).

Parameters:
Name Type Attributes Description
netadpIndex string

The network adapter index.

dnsAdds Array <optional>

If empty, enable DHCP.

Returns:
Type
boolean

(static) setIpAddress(netName, ipopt, maskopt, defGwopt, optionsopt) → {object|string}

Source:

Sets the IP address, SubNetMask, DefaultGateway.

Example
var net = Wsh.Net; // Shorthand

net.setIpAddress('Ethernet 1', '11.22.33.44', '255.255.0.0', '11.22.33.1')
// Returns: { err, stdout, stderr }
Parameters:
Name Type Attributes Default Description
netName string

The NetConnectionID of the network adapter.

ip string <optional>

If empty, enable DHCP.

mask string <optional>
'255.255.255.0'
defGw string <optional>
''
options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
runsAdmin boolean | undefined <optional>

true: as Admin, false: as User

isDryRun boolean <optional>
false

No execute, returns the string of command.

Returns:
Type
object | string

(static) setIpAddressesWithWMI(netName, ipopt, maskopt, defGwopt) → {boolean}

Source:

Set the IP address and the SubNetMask.

Parameters:
Name Type Attributes Default Description
netName string

The Network Adapter Index. 誤爆が怖いので操作するNetworkアダプタをIndexで指定する

ip string <optional>

指定なしでDHCPを有効にする

mask string <optional>
'255.255.255.0'
defGw string <optional>
''
Returns:
Type
boolean

(static) showIpConfigAll(optionsopt) → {void}

Source:

Shows the result of ipconfig /all on a window.

Example
var net = Wsh.Net; // Shorthand

net.showIpConfigAll(); // Displays a DOS window
Parameters:
Name Type Attributes Description
options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
winStyle number | string <optional>
'activeDef'

See Wsh.Constants.windowStyles.

Returns:
Type
void