I was working on a function like this and the service described in this post is the best solition:
In my country does not exist any internet provider that allows ssh connection to home but you can choose whatever (payed) service to have it up and working