NSString containing IvP4 of machine

Joined
Apr 24, 2010
Messages
5
Reaction score
0
Points
1
Location
Ireland
Your Mac's Specs
Dual 1GHz G4 OSX10.4.11
Sorry to be a pain with noob questions, but does anyone know
a way of returning an NSString object containing the LAN IP address
of the machine the app is running on ? ?

Thanks

Chris
 
OP
C
Joined
Apr 24, 2010
Messages
5
Reaction score
0
Points
1
Location
Ireland
Your Mac's Specs
Dual 1GHz G4 OSX10.4.11
It seems to be a good day for solving my own problems !
:D

After a couple of hours' fannying around, I found an easy way to
do this, although it may not be foolproof on every machine:

Use:

NSArray *mcAddresses = [NSHost addresses];
NSString *ipv4 = [mcAddresses objectAtIndex: 1];


The 0 index of the [NSHost addresses] array is always the ipv6 extended address.
The 1 index seems always to return the ipv4 address of the machine for
the current location setting in System Preferences > Network, which is what
most people will want, I guess.

Chris
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top