The attached script should do it. You'll need to have the "nc" (= netcat) and "ascii2binary" commands installed. On Debian, they are available in the distribution's standard package repository, so I expect they are available on Ubuntu too.
Run the script without any options, and it will tell you how to use it.
Another alternative is to use snmpget:
snmpget -Oeqv -v 2c -c public <printer-hostname-or-IP> .1.3.6.1.2.1.43.5.1.1.17.1
(The full name of that SNMP OID is:
.iso.org.dod.internet.mgmt.mib-2.printmib.prtGeneral.prtGeneralTable.prtGeneralEntry.prtGeneralSerialNumber.1 )