#navi(../)
* Win32_NetworkAdapterConfigurationのサンプルスクリプト [#s1402495]
WMIを使ったWin32_NetworkAdapterConfigurationでネットワークカードに関する情報を表示するサンプルスクリプトを以下に記します。

#contents
#htmlinsertpcsp(win-top.html,win-sp.html)

* 関連記事 [#g30f99f4]
-[[PowerShellでWMIを使用するサンプル>PowerShell/PowerShellでWMIを使用するサンプル]]
-[[Win32_ComputerSystemのサンプルスクリプト>WSH/Win32_ComputerSystemのサンプルスクリプト]]
-[[Win32_ComputerSystemProductのサンプルスクリプト>WSH/Win32_ComputerSystemProductのサンプルスクリプト]]
-[[Win32_OperatingSystemのサンプルスクリプト>WSH/Win32_OperatingSystemのサンプルスクリプト]]
-[[Win32_BIOSのサンプルスクリプト>WSH/Win32_BIOSのサンプルスクリプト]]
-[[Win32_LogicalDiskのサンプルスクリプト>WSH/Win32_LogicalDiskのサンプルスクリプト]]
-[[Win32_Processorのサンプルスクリプト>WSH/Win32_Processorのサンプルスクリプト]]
-[[Win32_NetworkAdapterConfigurationのサンプルスクリプト>WSH/Win32_NetworkAdapterConfigurationのサンプルスクリプト]]
-[[Win32_DiskDriveのサンプルスクリプト>WSH/Win32_DiskDriveのサンプルスクリプト]]

* Win32_NetworkAdapterConfigurationを使ったサンプルスクリプト [#u966a844]
以下にWin32_NetworkAdapterConfigurationを使用したサンプルスクリプトを記します。~
本サンプルスクリプトでは、以下の値を表示しています。
-IP
-アダプタ名
-サブネット
-MACアドレス
-デフォルトゲートウェイ
-DHCPサーバ
-DNSホスト名
-DNSドメイン

** サンプルスクリプト [#s8947c16]
#ref(net.vbs)
 hostname="."	' dotは自機を示す
 ' uid = "username"
 ' pwd = "password"
 Set oLocater = CreateObject("WbemScripting.SWbemLocator")
 Set oService = oLocater.ConnectServer(hostname, "root/cimv2")
 ' Set oService = oLocater.ConnectServer(hostname, "root/cimv2", uid, pwd)	'ユーザ、パスワード設定をする場合
 oService.Security_.ImpersonationLevel = 3	' デフォルト値は3のため省略可能
 
 Set items = oService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration", , 48)
 
 For Each item In items
   If Not IsNUll(item.IPAddress) Then
     For i = LBound(item.IPAddress) To UBound(item.IPAddress)
       WScript.Echo("IP: " & item.IPAddress(i))
       WScript.Echo("アダプタ名: " & item.Description(i))
       WScript.Echo("サブネット: " & item.IPSubnet(i))
       WScript.Echo("MACアドレス: " & item.MACAddress(i))
       If IsArray(item.DefaultIPGateway) Then
         For j = LBound(item.DefaultIPGateway) To UBound(item.DefaultIPGateway)
           WScript.Echo("デフォルトゲートウェイ: " & item.DefaultIPGateway(j))
         Next
       End If
       WScript.Echo("DHCPサーバ: " & item.DHCPServer(i))
       WScript.Echo("DNSホスト名: " & item.DNSHostname(i))
       WScript.Echo("DNSドメイン: " & item.DNSDomain(i))
     Next
   End If
 Next
 
 Set item = Nothing
 Set oService = Nothing
 Set oLocater = Nothing

** 実行例 [#da55e395]
cscriptを使用して実行した結果です。

 C:\Users\sakura\Desktop>cscript net.vbs
 Microsoft (R) Windows Script Host Version 5.8
 Copyright (C) Microsoft Corporation. All rights reserved.
 
 IP: 192.168.1.14
 アダプタ名: 1x1 11b/g/n ワイヤレス LAN PCI Express Half Mini カード アダプタ
 サブネット: 255.255.255.0
 MACアドレス: 00:00:00:00:00:00
 デフォルトゲートウェイ: 192.168.1.1
 デフォルトゲートウェイ: fe80::207:7dff:fe5c:aecf
 DHCPサーバ: 192.168.1.1
 DNSホスト名: THINKPAD
 DNSドメイン:
 IP: fe80::ed26:1852:578e:2bd9
 アダプタ名: 1x1 11b/g/n ワイヤレス LAN PCI Express Half Mini カード アダプタ
 サブネット: 64
 MACアドレス: 00:00:00:00:00:00
 デフォルトゲートウェイ: 192.168.1.1
 デフォルトゲートウェイ: fe80::207:7dff:fe5c:aecf
 DHCPサーバ: 192.168.1.1
 DNSホスト名: THINKPAD
 DNSドメイン:
 IP: 2001:c90:8025:d78a:ecd2:77cd:eaae:ffe4
 アダプタ名: 1x1 11b/g/n ワイヤレス LAN PCI Express Half Mini カード アダプタ
 サブネット: 128
 MACアドレス: 00:00:00:00:00:00
 デフォルトゲートウェイ: 192.168.1.1
 デフォルトゲートウェイ: fe80::207:7dff:fe5c:aecf
 DHCPサーバ: 192.168.1.1
 DNSホスト名: THINKPAD
 DNSドメイン:
 IP: 2001:c90:8025:d78a:ed26:1852:578e:2bd9
 アダプタ名: 1x1 11b/g/n ワイヤレス LAN PCI Express Half Mini カード アダプタ
 サブネット: 64
 MACアドレス: 00:00:00:00:00:00
 デフォルトゲートウェイ: 192.168.1.1
 デフォルトゲートウェイ: fe80::207:7dff:fe5c:aecf
 DHCPサーバ: 192.168.1.1
 DNSホスト名: THINKPAD
 DNSドメイン:
 IP: 192.168.56.1
 アダプタ名: VirtualBox Host-Only Ethernet Adapter
 サブネット: 255.255.255.0
 MACアドレス: 00:00:00:00:00:00
 DHCPサーバ:
 DNSホスト名: THINKPAD
 DNSドメイン:
 IP: fe80::d152:215b:8cda:2f01
 アダプタ名: VirtualBox Host-Only Ethernet Adapter
 サブネット: 64
 MACアドレス: 00:00:00:00:00:00
 DHCPサーバ:
 DNSホスト名: THINKPAD
 DNSドメイン:

以上、Win32_NetworkAdapterConfigurationを使ったサンプルスクリプトでした。

#htmlinsertpcsp(win-btm.html,win-sp.html)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS