What does the hostname command return on your system ? If this is returning localhost you will get 127.0.0.1 as the related IP.
My idea is to find the machines hostname then use gethostbyname to return the IP address (in a binary form). gethostbyname is using your OS' idea of name resolution so this will have to work (try to ping your own host). The unpack splits this into four decimal fields and the join prints them all out with dots between.
|