retrieving your IP address
retrieving your IP address
- Subject: retrieving your IP address
- From: Jeremy Faller <email@hidden>
- Date: Tue, 22 Oct 2002 21:46:14 -0400
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] initWith
Data:[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.