Re: retrieving your IP address
Re: retrieving your IP address
- Subject: Re: retrieving your IP address
- From: Kris Amico <email@hidden>
- Date: Tue, 22 Oct 2002 19:06:01 -0700
If you don't mind using SystemConfiguration.framework, you could use
SCDynamicStoreCopyValue to get the dictionary at:
State:/Network/Global/IPv4
From that dictionary, grab the service ID at "PrimaryService" and then copy
the dynamic store data at the key:
State:/Network/Service/[your service id]/IPv4
In that dictionary, the IP addresses are stored at "Addresses".
If you want a good look at what information you can get at in the dynamic
store, use SCDynamicStoreCopyKeyList then SCDynamicStoreCopyMultiple and
dump the data somewhere. The cool thing about using SC for this is that you
can register to be notified when the IPv4 information changes so that you
can have the very latest data when, say, the Customer switches to a
different network location.
On 10/22/02 6:46 PM, "Jeremy Faller" <email@hidden> wrote:
>
All:
>
>
I am trying to retrieve my IP address from my host, and the easiest way
>
I could find was to use /usr/sbin/ipconfig -- unfortunately, I have an
>
error. I am trying to call ipconfig this way:
>
>
NSTask *ipconfig = [[NSTask alloc] init];
>
NSFileHandle *fileHandle = [[NSPipe pipe] fileHandleForReading];
>
NSString *str;
>
NSString *args[] = { @"getifaddr", @"en0" };
>
NSArray *array;
>
>
// setup the launch array
>
array = [[NSArray alloc] initWithObjects:args count:2];
>
>
// Get the ip address
>
[ipconfig setStandardOutput:fileHandle];
>
[ipconfig setLaunchPath:@"/usr/sbin/ipconfig"];
>
[ipconfig setArguments:array];
>
[ipconfig launch];
>
[ipconfig waitUntilExit];
>
NSLog(@"finished task!");
>
>
// Read the data
>
// BEGIN ERROR
>
str = [[NSString alloc] initWithData:[fileHandle availableData]
>
encoding:NSASCIIStringEncoding];
>
// END ERROR
>
NSLog(@"The string received %@", str);
>
[str release];
>
>
[ipconfig release];
>
[array release];
>
>
My file handle is never coming back. Does anyone know why?
>
Additionally, is there an easier way to get your own IP? (I'm sure
>
there is, but I haven't been able to track one down...)
>
>
Thanks for all help in advance.
>
>
>
Jeremy Faller
>
email@hidden
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
--
Kris Amico <email@hidden>, AIM: Kris Amico
Senior Software Engineer
Macintosh Client Software Development
EarthLink, Inc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.