473,322 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Determining whether given IP exist in CIDR IP Range

ashitpro
542 Expert 512MB
I want to check whether given IP exist in CIDR range..

e.g.

IP is 192.168.1.3
CIDR is 192.168.1.0/24

here according to CIDR
lower ip is 192.168.1.1
higher ip is 192.168.1.254

So if I give input as 192.168.1.3 and my cidr. It should return true.
Is there any facility in C/C++
Jan 30 '08 #1
2 6929
sicarie
4,677 Expert Mod 4TB
Doesn't seem like that would be a very difficult function to program, though I honestly haven't gone looking through many libraries to see if that does exist. Did you do a Google search for this?
Jan 30 '08 #2
ashitpro
542 Expert 512MB
Doesn't seem like that would be a very difficult function to program, though I honestly haven't gone looking through many libraries to see if that does exist. Did you do a Google search for this?
Yes, I did googling for this..
I got few solutions too..But they were too lengthy..
Eventually I've found out my own way to do it. I'd like to write here about it. May be helpful for other people.

e.g. CIDR is 192.168.9.0/24 and IP to check is 192.168.9.34.

step 1: convert 192.168.9.0 to unsigned long int by inet_aton function..Result will be LOWERIP.
step 2. calculate HIGHERIP = LOWERIP + (pow(2,32-mask value)-1)
Here mask value is 24 as per our example.
step 3. Convert your IP(address to check) in unigned long int format. Say it as MYIP
step 4. Now just check for LOWERIP < MYIP < HIGHERIP
If this is the case..then your IP present inside the range.
Jan 31 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: BigMan | last post by:
Are these two lines equivalent? #ifdef MACRO #if MACRO==0
9
by: Christopher Benson-Manica | last post by:
I have the following situation: Page A opens a window named 'foo'. Page A then reloads itself. Is there a way for the reloaded Page A to determine whether there is an open window named 'foo',...
3
by: Gareth Tonnessen | last post by:
I need to have a clean way to determine whether a query exists without trying to open it and getting an error message. Is there a simple way to determine whether an object exists in a database?...
2
by: Laszlo Szijarto | last post by:
Using reflection, I am iterating through an array of FieldInfo objects and wish to determine whether any given field represents a signed or an unsigned variable (makes a difference in terms of how...
4
by: Claire | last post by:
How do I determine whether Im running in debug or release mode from code please. thanks Claire
2
by: Dan | last post by:
How does one do this?
4
by: RossettoeCioccolato | last post by:
How do I determine programmatically whether or not the VC8 C/C++ SxS assemblies currently are installed on a system? Regards, Rossetoecioccolato.
4
by: ug26jhw | last post by:
Is there any way to determine whether an element in a document exists. I have some code like this where the variable i changes: if(document.getElementById('pref'+i).innerHTML... When it...
4
by: Nathan Sokalski | last post by:
When determining whether a String can be converted to a DateTime, you can use the IsDate() method. However, I would also like to know whether the string is a date, a time, or both a date and a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.