Originally posted by zachs:
I'm sure this has been asked before, but how do I get my IP address so that I can then display in as an NSString?
Any help is appreciated.
Thanks.
Well you could use NSHost
[[NSHost curentHost] addresses]
but many users have reported that it only returns 127.0.0.1 (not for me tho.)
Anyway, for me it returns a NSArray of 2 NSStrings "127.0.0.1" which is localhost, and "192.168.123.185" which is my "lan address" ( nobody outside of your networks could contact you with that address )
I guess what you're interested in would be the "external" IP address (the one people outside of your lan see) something like 65.74.21.11
Well the easiest way I know would be to parse the html at
http://checkip.dyndns.org (which isnt really hard)
it's pretty easy to fetch, ( use NSString's initwithContentsOfURL, CURLHandle (curlhandle.sf.net) or even a 10 lines/max bsd socket call )
I hope that helps!