Skip to content

Instantly share code, notes, and snippets.

@nyerup
Last active March 26, 2023 13:58
Show Gist options
  • Save nyerup/7689129 to your computer and use it in GitHub Desktop.
Save nyerup/7689129 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
#
# Uses ipmitool(1) to display a string of text on
# the front chassis display of Dell PowerEdge
# servers.
#
# Jesper Nyerup <[email protected]>
my $ipmitool = '/usr/bin/ipmitool';
my @chararray = split(//, join(' ', @ARGV));
usage() if (@chararray == 0 or @chararray > 14);
system("$ipmitool raw 0x6 0x58 193 0x0 0x0 ".
sprintf('0x%x ', scalar(@chararray)).
join(' ', map { sprintf('0x%x', ord($_)) } @chararray));
system("$ipmitool raw 0x6 0x58 0xc2 0x0 0x0 ".
"0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0");
sub usage {
print <<EOF;
Usage: $0 <string>
Max. 14 characters
EOF
exit 1
}
@sfc9982
Copy link

sfc9982 commented Mar 26, 2023

There are 2 registers:

0        Which chunk of 16 bytes of text you're editing (62 bytes are allowed).
0        Text encoding. This should always be 0 for ASCII.

They are a control bit of buffer inside IPMI. The LCD string is a buffer which has a width of 16 (each chunk), and has a height.
You can use the chunk register to control which row you are editing. And the text coding and length register only exist in the first row.
We can use it as a pointer to set string longer than 14 characters.

Python PoC

# -*- coding: UTF-8 -*-
# !/usr/bin/python

host = '*.*.*.*'
user = 'root'
passwd = '******'
lcd = 'Dell PowerEdge R710 - VMware vSphere - Misaka Network, Inc.'

strHex = ''
cmd_prefix = 'ipmitool -I lanplus -H ' + host + ' -U ' + user + ' -P ' + passwd
LCD_len = len(lcd)
cmd = cmd_prefix + ' raw 0x6 0x58 193'

for x in lcd:
    strHex += hex(ord(x))
    strHex += " "

if LCD_len <= 14:
    print(cmd_prefix + ' raw 0x6 0x58 193 0 0 ' + str(LCD_len) + ' ' + strHex)
else:
    first = lcd[:14]
    strFirst = ''
    for x in first:
        strFirst += hex(ord(x))
        strFirst += " "
    print(cmd_prefix + ' raw 0x6 0x58 193 0 0 ' + str(LCD_len) + ' ' + strFirst)
    lcd = lcd[14:]
    num = LCD_len - 14
    for i in range(num // 16 + 1):
        strHex = ''
        for x in lcd[i * 16:min(num + 1, (i + 1) * 16)]:
            strHex += hex(ord(x))
            strHex += ' '
        print(cmd_prefix + ' raw 0x6 0x58 193 ' + str(i + 1) + ' ' + strHex)

@sfc9982
Copy link

sfc9982 commented Mar 26, 2023

On newer devices you can even use racadm set System.LCD.UserDefinedString "foobar"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment