Salaam Mansoor,
Yes, from Australia to Tehran, you can buy your ticket online. Almost all fares on Emirates allow you to get a free stopover in Dubai. Just use the multi-city search function and you can put in BNE-DXB, DXB-THR, THR-BNE if stopping on the outbound or you can simply use the stopover tab in the multi-city search and do it that way. If you have an Iranian passport then yes, you would need a visa for Dubai. The hotel you are staying at can arrange this for you or if you are visiting a friend, your friend can sponsor you. The processing time is about 3 working days and you have to pay 450 dirhams for the visa. You may also have to make a deposit of 5,000 dirhams which is refunded when you depart Dubai.
If you have a passport from a GCC country or:
France, Italy, Germany, the Netherlands, Belgium, Luxembourg, Switzerland, Austria, Sweden, Norway, Denmark, Portugal, Ireland, Greece, Cyprus, Finland, Malta, Spain, Monaco, Vatican City, Iceland, Andorra, San Marino, Liechtenstein, United States (US), Canada, Australia, New Zealand, Japan, Brunei, Singapore, Malaysia and Hong Kong, then you do not need a visa.