Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-04-2010, 12:52 AM   #1 (permalink)
el guaje
 
kevinyide's Avatar
 
Join Date: Jun 2010
Posts: 243
kevinyide is on a distinguished road
Send a message via Yahoo to kevinyide
Exclamation IP address range match

How do i check if a particular IP address, obtained as NSString say zz.zz.zz.zz lie between custom allowable range of zz.zz.zz.xx & zz.zz.zz.yy ??
kevinyide is offline   Reply With Quote
Old 07-04-2010, 06:10 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2008
Location: London/Peterborough
Posts: 562
QuantumDoja is on a distinguished road
Default

I'm sure there is a better way, but you could split the strings on the "." and then compare the values in the resulting array...ie:

Code:
int[] given = split{"100.122.100.124"}

int[] ip1 = split{"100.122.100.122"}
int[] ip2 = split{"100.122.100.126"}

//check first 3 are equal, then check the last number?
if (given[3] >= ip1[3] && given[3] <= ip2[3]) {
 //in range
}
or something like that anyway.
QuantumDoja is offline   Reply With Quote
Old 07-05-2010, 12:23 AM   #3 (permalink)
el guaje
 
kevinyide's Avatar
 
Join Date: Jun 2010
Posts: 243
kevinyide is on a distinguished road
Send a message via Yahoo to kevinyide
Default

i shall try that out, im sure there must be a better way too, but found none on the forums...
Thanks,
Kevin
kevinyide is offline   Reply With Quote
Old 07-05-2010, 12:06 PM   #4 (permalink)
el guaje
 
kevinyide's Avatar
 
Join Date: Jun 2010
Posts: 243
kevinyide is on a distinguished road
Send a message via Yahoo to kevinyide
Default

OK for an ip xx.xx.xx.xx that i need to check for range between xx.xx.xx.yy & xx.xx.xx.zz i have

Code:
NSArray *checkIP = [[NSArray alloc]initWithArray:[myIpString componentsSeparatedByString:@"."]];
Likewise i have NSArrays for the startIP & endIP range.
How do i check if the first three numbers of checkIP xx.xx.xx.xx are same as that of startIP &/OR endIP before i proceed to check the last number in the ip?
I dont want to check it number by number using objectAtIndex though i could. I've read the documentation for NSIndexSet to try and use it like if [checkIP objectsAtIndexes:NSIndexSet] (for array indexes 1-3) bt i hvnt been able to use it... what am i missing? hw is the IndexSet to be used?
All im looking for is minimum lines of code to check the first 3 numbers of someIP are same as first three numbers of my IP range limits.
kevinyide is offline   Reply With Quote
Old 07-08-2010, 06:00 AM   #5 (permalink)
el guaje
 
kevinyide's Avatar
 
Join Date: Jun 2010
Posts: 243
kevinyide is on a distinguished road
Send a message via Yahoo to kevinyide
Default

anyone having any idea how i could check a specified number of objects between two NSArray's being equal in value or not?
kevinyide is offline   Reply With Quote
Old 07-08-2010, 07:18 AM   #6 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 138
SpaceAce is on a distinguished road
Default

Quote:
Originally Posted by kevinyide View Post
anyone having any idea how i could check a specified number of objects between two NSArray's being equal in value or not?
Sure, you are thinking way too complicated here.

All you need to do is to calculate the integer representation for the 3 IPs and then do a simple greater / equal / smaller comparison!

So: Include <arpa/inet.h>, use either function inet_aton() (which is deprecated but still works fine) or inet_pton() to convert the first, last and check-IP x.x.x.x to integers and then compare check_ip < start_ip || check_ip > end_ip

Hope this helps.

Last edited by SpaceAce; 07-08-2010 at 08:18 AM.
SpaceAce is offline   Reply With Quote
Reply

Bookmarks

Tags
ip address, range match, validation

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 327
6 members and 321 guests
anothermine, Chickenrig, givensur, michaelhansen, PixelInteractive, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,892
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:27 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0