「VBScript入門」IPアドレスとMAC物理アドレスの情報を取得する方法
説明
winmgmts:WMI(Windows Management Instrumentation)
\\.\ 現在のコンピュータ
root\cimv2 オブジェクトの名前空間
該当する全てのオブジェクト
Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True
使用例
'IPアドレス取得の関数定義 Function GetIpFunc(ComputerName) Dim objWMIService,cftItems,objItem,objAddress 'ローカルコンピュータ 名前空間\root\cimv2 Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2") Set cftItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") For Each objItem in cftItems For Each objAddress in objItem.IPAddress If objAddress <> "" then 'ipaddress取得 GetIpFunc= objAddress Exit For End If Next Exit For Next End Function 'macアドレス取得関数の定義 Function GetMacFunc(ComputerName) Dim objWMIService,cftItems,objItem,objAddress Set objWMIService = GetObject("winmgmts:\\" & ComputerName & "\root\cimv2") Set cftItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") For Each objItem in cftItems For Each objAddress in objItem.IPAddress If objAddress <> "" then 'macaddress取得 GetMacFunc= objItem.MACAddress Exit For End If Next Exit For Next End Function Wscript.echo "ip address: "&GetIpFunc(".") Wscript.echo "mac address: "&GetMacFunc(".")
実行結果
ip address:192.168.xxx.xxx
mac address:84:BD:xx:xx:xx:xx