Dial these in the Phone app. Codes vary by model and region, and some carriers disable them.
*#06#: show the IMEI and serial number
*#0*#: hardware test menu (screen colours, touch, speaker, vibration, sensors, cameras)
*#1234#: firmware versions (AP, CP, CSC), useful for choosing the right firmware
*#0228#: battery status
*#7353#: quick test menu on some older models
Codes that change settings or reset the phone are not listed on purpose. A wrong code can erase the phone.