• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to get my IP Address ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get my IP Address ?


  • Subject: Re: How to get my IP Address ?
  • From: "Alex v.Below" <email@hidden>
  • Date: Sat, 27 Nov 2004 17:00:45 +0100

127.0.0.1 is your IP! Well, actually it is only one of your IP addresses, and this is where the trouble starts.

Here is how I do it (the system configuration framework is your friend!), and the link points to where I got my knowledge from.

Hope that helps,

Alex

+ (NSArray *) currentIP4Addresses
{
// http://cocoa.mamasam.com/COCOADEV/2001/11/2/18325.php

NSMutableArray * addresses;
SCDynamicStoreRef
dynRef=SCDynamicStoreCreate(kCFAllocatorSystemDefault,
(CFStringRef)@"Whatever you want", NULL, NULL);
// Get all available interfaces IPv4 addresses
NSArray *interfaceList=(NSArray *)
SCDynamicStoreCopyKeyList(dynRef,(CFStringRef)@"State:/Network/Service/..*/IPv4");

NSEnumerator *interfaceEnumerator=[interfaceList objectEnumerator];
addresses = [NSMutableArray arrayWithCapacity:[interfaceList count]];
NSString *interface;

while(interface=[interfaceEnumerator nextObject]) {
NSDictionary *interfaceEntry=(NSDictionary
*)SCDynamicStoreCopyValue(dynRef,(CFStringRef)interface);
NSString * interfaceName = [interfaceEntry objectForKey:kInterfaceNameKey];
NSArray *adList=[interfaceEntry objectForKey:kAddressesKey];

[addresses addObject:
[NSDictionary dictionaryWithObjectsAndKeys:
interfaceName, kInterfaceNameKey,
adList, kAddressesKey, nil]];
NSLog(@"%@ -> addresses: %@",interfaceName, adList);

[interfaceEntry release]; // must be released
}

[interfaceList release]; // must be released
return [NSArray arrayWithArray:addresses];
}


Am 27.11.2004 um 16:53 schrieb Mark Gilbert:

Folks.

I have setup a very simple socket from one machine to another. I want to send back very very simple HTML.

within the HTML I need to include my own IP address, but I am not sure how to get it.

I tried gethostbyname("localhost"), but this returns 127.0.0.1 which works on the local machine, but is not my address on the network.

For example, I happen to know that my machine is 192.169.1.104, and I can reach my machine remotely using this. How does my app learn that this is my address ?

I am sure its a really simple trick, but I am obviously missing it.

Cheers

Mark Gilbert.
--
email@hidden
Tel: +44 208 340 5677
fax: +44 870 055 7790
http://www.gallery.co.uk
New Product ! - Zen MetaCorder
Location Sound Field Recorder
http://www.metacorder.info
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >How to get my IP Address ? (From: Mark Gilbert <email@hidden>)

  • Prev by Date: How to get my IP Address ?
  • Next by Date: Re: Asm question (port from linux ppc)
  • Previous by thread: How to get my IP Address ?
  • Next by thread: Re: How to get my IP Address ?
  • Index(es):
    • Date
    • Thread