• 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
retrieving your IP address
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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] 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.

  • Follow-Ups:
    • Re: retrieving your IP address
      • From: Andreas Monitzer <email@hidden>
    • Re: retrieving your IP address
      • From: Kris Amico <email@hidden>
  • Prev by Date: Re: Can't find Framework
  • Next by Date: Re: retrieving your IP address
  • Previous by thread: Re: NSTimer "takes over" CPU everytime it repeats?
  • Next by thread: Re: retrieving your IP address
  • Index(es):
    • Date
    • Thread