It doesn't work because you can't do it. I'm not sure what that code on your link is supposed to be doing, but I can tell you that you can't display an IP with Javascript. You need a server side language. You could use AJAX if you wanted, but you'd still need a server side language.
This is how to display an IP with PHP:
PHP Code:
<?php
echo $_SERVER['REMOTE_ADDR'];
?>