• 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: IP Address - revisited
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IP Address - revisited


  • Subject: Re: IP Address - revisited
  • From: Larry Fransson <email@hidden>
  • Date: Wed, 21 Jul 2004 23:01:50 -0700

On Jul 21, 2004, at 21:02, David Cornell wrote:

> Given the following how would i print out only IPV4 addresses while
> excluding
> IPV6 addresses and 127.0.0.1?
>
> NSEnumerator *contents = [[currenthost addresses] objectEnumerator];
> NSString *address;
> while ((address = [contents nextObject]))
> {
> //...
> }

Given that IPv6 addresses are not allowed to contain periods, you could
exclude anything not containing a period. Matching 127.0.0.1 for
exclusion is easy. If I remember correctly, a continue statement will
continue (imagine that!) to the next iteration of the loop after you
have matched one of the addresses you want to exclude. If you don't
want to exclude it, you print it, like this:

NSArray *adds = [[NSHost currentHost] addresses];
NSEnumerator *e = [adds objectEnumerator];
id o;
while(o = [e nextObject]) {
if([o isEqualToString:@"127.0.0.1"]) continue;
else if([o rangeOfString:@"."].location == NSNotFound) continue;
NSLog(@"%@", o);
}

Larry Fransson
Seattle, WA
_______________________________________________
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: IP Address - revisited
      • From: Scott Judd <email@hidden>
References: 
 >IP Address - revisited (From: "David Cornell" <email@hidden>)

  • Prev by Date: Re: Tiger for ASD?
  • Next by Date: Using .nib files for non IB objects
  • Previous by thread: IP Address - revisited
  • Next by thread: Re: IP Address - revisited
  • Index(es):
    • Date
    • Thread