勉強を兼ねてWindowsのネットワークアダプタ情報を取得するVBScriptです。
Win32_NetworkAdapter classを利用しています。
Win32_NetworkAdapter class
https://msdn.microsoft.com/library/windows/hardware/aa394216
The Win32_NetworkAdapter class is deprecated. Use the MSFT_NetAdapter class instead. The Win32_NetworkAdapterWMI class represents a network adapter of a computer running a Windows operating system.
Win32_NetworkAdapter only supplies IPv4 data. For more information, see IPv6 and IPv4 Support in WMI.
Win32_NetworkAdapterは廃止予定なので代わりにSFT_NetAdapter classを使ってとあります。
Windows 10 Pro(Build 15063)で確認しました。
参考)ネットワーク アダプタ プロパティの列挙
https://gallery.technet.microsoft.com/scriptcenter/f6531443-3e88-46f7-8b1b-e8333b56d39a
サンプルでは有線LANアダプタのみを表示するようにしています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
On Error Resume Next Dim s strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where AdapterTypeID=0") For Each objItem in colItems s = "Adapter Type: " & objItem.AdapterType & vbCRLF Select Case objItem.AdapterTypeID Case 0 strAdapterType = "Ethernet 802.3" Case 1 strAdapterType = "Token Ring 802.5" Case 2 strAdapterType = "Fiber Distributed Data Interface (FDDI)" Case 3 strAdapterType = "Wide Area Network (WAN)" Case 4 strAdapterType = "LocalTalk" Case 5 strAdapterType = "Ethernet using DIX header format" Case 6 strAdapterType = "ARCNET" Case 7 strAdapterType = "ARCNET (878.2)" Case 8 strAdapterType = "ATM" Case 9 strAdapterType = "Wireless" Case 10 strAdapterType = "Infrared Wireless" Case 11 strAdapterType = "Bpc" Case 12 strAdapterType = "CoWan" Case 13 strAdapterType = "1394" End Select s = s & "Adapter Type Id: " & strAdapterType & vbCRLF s = s & "AutoSense: " & objItem.AutoSense & vbCRLF s = s & "Description: " & objItem.Description & vbCRLF s = s & "Device ID: " & objItem.DeviceID & vbCRLF s = s & "Index: " & objItem.Index & vbCRLF s = s & "MAC Address: " & objItem.MACAddress & vbCRLF s = s & "Manufacturer: " & objItem.Manufacturer & vbCRLF s = s & "Maximum Number Controlled: " & objItem.MaxNumberControlled & vbCRLF s = s & "Maximum Speed: " & objItem.MaxSpeed & vbCRLF s = s & "Name: " & objItem.Name & vbCRLF s = s & "Net Connection ID: " & objItem.NetConnectionID & vbCRLF s = s & "Net Connection Status: " & objItem.NetConnectionStatus & vbCRLF For Each strNetworkAddress in objItem.NetworkAddresses s = s & "NetworkAddress: " & strNetworkAddress & vbCRLF Next s = s & "Permanent Address: " & objItem.PermanentAddress & vbCRLF s = s & "PNP Device ID: " & objItem.PNPDeviceID & vbCRLF s = s & "Product Name: " & objItem.ProductName & vbCRLF s = s & "Service Name: " & objItem.ServiceName & vbCRLF s = s & "Speed: " & objItem.Speed & vbCRLF Wscript.Echo s Next |
NetConnectionIDプロパティがネットワーク接続に表示される名称のようです。
NetworkAddressesプロパティですが上記Win32_NetworkAdapter classの説明サイトに
This property has not been implemented yet. It returns a NULL value by default.
とありました。これを見つけられずに延々悩んでました。
絶対に何か表示されるはず、表示されないのはスクリプトが間違っているとorz