[root@localhost ~]# yum install -y ipmitool #安裝這個包python
電源相關:ios
#開啓電源shell
ipmitool -I lanplus -H 10.41.1.41 -U root -P root power on服務器
#關閉電源
session
ipmitool -I lanplus -H 10.41.1.41 -U root -P root power offide
#重啓電源
.net
ipmitool -I lanplus -H 10.41.1.41 -U root -P root power resetblog
#查看電源狀態ip
ipmitool -I lanplus -H 10.41.1.41 -U root -P root power statuscmd
啓動項相關:
#設置爲BIOS啓動
ipmitool -I lanplus -H 10.41.1.41 -U root -P root chassis bootparam set bootflag force_bios
#設置爲pxe啓動
ipmitool -I lanplus -H 10.41.1.41 -U root -P root chassis bootparam set bootflag force_pxe
#設置爲光盤啓動
ipmitool -I lanplus -H 10.41.1.41 -U root -P root chassis bootparam set bootflag force_cdrom
#設置爲硬盤啓動
ipmitool -I lanplus -H 10.41.1.41 -U root -P root chassis bootparam set bootflag force_disk
#重啓BMC
ipmitool -I lanplus -H 10.41.1.41 -U root -P root mc reset cold
#修改BMC密碼
ipmitool -I lanplus -H 10.41.1.41 -U root -P root user set password 2 new_password #new_password 這個是新密碼
#遠程文本重定向 重啓服務器就能看到畫面
ipmitool -I lanplus-H 10.41.1.41 -U root -P root sol activate
#當有這個錯誤時 Info: SOL payload already active on another session
ipmitool -I lanplus-H 10.41.1.41 -U root -P root sol deactivate #這命令是踢出其餘的人會話
#獲取mac地址 有些機型不許 我這個是dell的服務器 華爲服務器也可使用
"""ipmitool -I lanplus -H 10.41.1.41 -U root -P root lan print |grep "MAC Address"|awk '{print $NF}'"""
python 腳本
from subprocess import Popen, PIPE cmd = """ipmitool -I lanplus -H 10.41.1.41 -U root -P root lan print |grep "MAC Address"|awk '{print $NF}'""" text = Popen(cmd, stdout=PIPE, shell=True).stdout.read() prefix_mac = text[:-3] last_two = text[-2:] plus_one = int(last_two, 16) - 2 plus_one2 = int(last_two, 16) - 1 new_last_two = hex(plus_one)[2:] new_last_two2 = hex(plus_one2)[2:] if len(new_last_two) == 1: new_last_two = '0' + new_last_two if len(new_last_two2) == 1: new_last_two2 = '0' + new_last_two2 new_mac = prefix_mac.replace(':','') + new_last_two new_mac2 = prefix_mac.replace(':','') + new_last_two2 print(new_mac,new_mac2)
獲取網卡1mac地址和網卡2mac地址
參考:
http://blog.csdn.net/zygblock/article/details/53431972