Re: IP Address - revisited
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.