The reason there are two seemingly different ways to do this is simply this:

Merlin83 is talking about a GSM type mobile phone, where *#06# is a GSM standard command to display the IMEI number. By the way, *#06# is part of a large library of GSM primitives to envoke GSM features (eg., *#32#____# where _____ is a number to forward your calls to).

Cid Highwind is talking about CDMA type mobile phones which store a similar ESN Number.