Wiki source code of IPMI

Last modified by Sebastian Marsching on 2022/12/23 00:18

Show last authors
1 {{toc/}}
2
3 # Finding the IPMI address for a system
4
5 On modern versions of Windows, the IPMI MAC and IP address can be determined without having to instally any software through a [PowerShell script that I found in a blog](https://michlstechblog.info/blog/windows-read-the-ip-address-of-a-bmc-board/):
6
7 ```ps1
8 # Get the Class instance
9 $oIPMI=Get-WmiObject -Namespace root\WMI -Class MICROSOFT_IPMI
10 # Some constants
11 # <a title="Microsoft In Band Management" href="http://gallery.technet.microsoft.com/scriptcenter/In-Band-Management-using-88e221b8" target="_blank">Source</a>
12 [byte]$BMCResponderAddress = 0x20
13 [byte]$GetLANInfoCmd = 0x02
14 [byte]$GetChannelInfoCmd = 0x42
15 [byte]$SetSystemInfoCmd = 0x58
16 [byte]$GetSystemInfoCmd = 0x59
17 [byte]$DefaultLUN = 0x00
18 [byte]$IPMBProtocolType = 0x01
19 [byte]$8023LANMediumType = 0x04
20 [byte]$MaxChannel = 0x0b
21 [byte]$EncodingAscii = 0x00
22 [byte]$MaxSysInfoDataSize = 19
23 # Find the first channel
24 [byte[]]$RequestData=@(0)
25 $oMethodParameter=$oIPMI.GetMethodParameters("RequestResponse")
26 $oMethodParameter.Command=$GetChannelInfoCmd
27 $oMethodParameter.Lun=$DefaultLUN
28 $oMethodParameter.NetworkFunction=0x06
29 $oMethodParameter.RequestData=$RequestData
30 $oMethodParameter.RequestDataSize=$RequestData.length
31 $oMethodParameter.ResponderAddress=$BMCResponderAddress
32 # http://msdn.microsoft.com/en-us/library/windows/desktop/aa392344%28v=vs.85%29.aspx
33 $RequestData=@(0)
34 [Int16]$iLanChannel=0
35 [bool]$bFoundLAN=$false
36 for(;$iLanChannel -le $MaxChannel;$iLanChannel++){
37 $RequestData=@($iLanChannel)
38 $oMethodParameter.RequestData=$RequestData
39 $oMethodParameter.RequestDataSize=$RequestData.length
40 $oRet=$oIPMI.PSBase.InvokeMethod("RequestResponse",$oMethodParameter,(New-Object System.Management.InvokeMethodOptions))
41 #$oRet
42 if($oRet.ResponseData[2] -eq $8023LANMediumType){
43 $bFoundLAN=$true
44 break;
45 }
46 }
47 # If the LAN channel was found, get the network parameters
48 $oMethodParameter.Command=$GetLANInfoCmd
49 $oMethodParameter.NetworkFunction=0x0c
50 if($bFoundLAN){
51 $RequestData=@($iLanChannel,3,0,0)
52 $oMethodParameter.RequestData=$RequestData
53 $oMethodParameter.RequestDataSize=$RequestData.length
54 $oRet=$oIPMI.PSBase.InvokeMethod("RequestResponse",$oMethodParameter,(New-Object System.Management.InvokeMethodOptions))
55 write-host ("IP Address: "+$oRet.ResponseData[2]+"."+$oRet.ResponseData[3]+"."+$oRet.ResponseData[4]+"."+ $oRet.ResponseData[5] )
56 $RequestData=@($iLanChannel,6,0,0)
57 $oMethodParameter.RequestData=$RequestData
58 $oMethodParameter.RequestDataSize=$RequestData.length
59 $oRet=$oIPMI.PSBase.InvokeMethod("RequestResponse",$oMethodParameter,(New-Object System.Management.InvokeMethodOptions))
60 write-host ("Subnet Mask: "+$oRet.ResponseData[2]+"."+$oRet.ResponseData[3]+"."+$oRet.ResponseData[4]+"."+ $oRet.ResponseData[5] )
61 $RequestData=@($iLanChannel,5,0,0)
62 $oMethodParameter.RequestData=$RequestData
63 $oMethodParameter.RequestDataSize=$RequestData.length
64 $oRet=$oIPMI.PSBase.InvokeMethod("RequestResponse",$oMethodParameter,(New-Object System.Management.InvokeMethodOptions))
65 # Format http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
66 write-host ("MAC Address: "+("{0:x2}:{1:x2}:{2:x2}:{3:x2}:{4:x2}:{5:x2}" -f $oRet.ResponseData[2], $oRet.ResponseData[3],$oRet.ResponseData[4], $oRet.ResponseData[5], $oRet.ResponseData[6], $oRet.ResponseData[7]))
67 }
68 ```