[root@localhost ~]# yum install -y ipmitool #安装这个包
电源相关:
#开启电源
ipmitool -I lanplus -H 10.41.1.41 -U root -P root power on
#关闭电源
ipmitool -I lanplus -H 10.41.1.41 -U root -P root power off
#重启电源
ipmitool -I lanplus -H 10.41.1.41 -U root -P root power reset
#查看电源状态
ipmitool -I lanplus -H 10.41.1.41 -U root -P root power status
启动项相关:
#设置为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
转载于:https://blog.51cto.com/xiaocuik/1975216