Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
NSString containing IvP4 of machine
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="chriseccles" data-source="post: 1042237" data-attributes="member: 152222"><p>It seems to be a good day for solving my own problems !</p><p><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big grin :D" loading="lazy" data-shortname=":D" /></p><p></p><p>After a couple of hours' fannying around, I found an easy way to</p><p>do this, although <strong><em>it may not be foolproof</em></strong> on every machine:</p><p></p><p>Use:</p><p></p><p><span style="font-family: 'Courier New'"><span style="font-size: 12px"><span style="color: Blue">NSArray *mcAddresses = [NSHost addresses];</span></span></span></p><p><span style="font-family: 'Courier New'"><span style="font-size: 12px"><span style="color: Blue">NSString *ipv4 = [mcAddresses objectAtIndex: 1];</span></span></span></p><p></p><p>The 0 index of the <strong>[NSHost addresses]</strong> array is always the ipv6 extended address.</p><p>The 1 index seems always to return the ipv4 address of the machine for</p><p>the current location setting in System Preferences > Network, which is what</p><p>most people will want, I guess.</p><p></p><p>Chris</p></blockquote><p></p>
[QUOTE="chriseccles, post: 1042237, member: 152222"] 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 [B][I]it may not be foolproof[/I][/B] on every machine: Use: [FONT="Courier New"][SIZE="3"][COLOR="Blue"]NSArray *mcAddresses = [NSHost addresses]; NSString *ipv4 = [mcAddresses objectAtIndex: 1];[/COLOR][/SIZE][/FONT] The 0 index of the [B][NSHost addresses][/B] 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 [/QUOTE]
Verification
Name this item 🌈
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
NSString containing IvP4 of machine
Top