Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > IP Address

IP Address
Thread Tools
zachs
Mac Elite
Join Date: May 2002
Location: New York City
Status: Offline
Reply With Quote
May 5, 2003, 05:44 PM
 
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.
     
ambush
Banned
Join Date: Apr 2002
Location: -
Status: Offline
Reply With Quote
May 5, 2003, 07:31 PM
 
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!
     
zachs  (op)
Mac Elite
Join Date: May 2002
Location: New York City
Status: Offline
Reply With Quote
May 5, 2003, 09:46 PM
 
Thanks. I'll try that.

(Luckily I built in a parse HTML feature in my app, Poster.)

     
ambush
Banned
Join Date: Apr 2002
Location: -
Status: Offline
Reply With Quote
May 5, 2003, 10:21 PM
 
Originally posted by zachs:
Thanks. I'll try that.

(Luckily I built in a parse HTML feature in my app, Poster.)

Well it's basically a three lines NSScanner trick, so...

anyway
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:52 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,