473,395 Members | 1,466 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,395 software developers and data experts.

Check if an IP address is in a range.

Is there a way to check if an IP address is in a subnet range? say I have
the IP

10.10.0.0 and a subnet of 255.255.0.0 and am given the IP 10.10.50.1 and
want to verify that it is in that range.. thanks!
Aug 28 '07 #1
3 13406
On Mon, 27 Aug 2007 23:28:47 -0400, "Smokey Grindel"
<no****@nospam.comwrote:
>Is there a way to check if an IP address is in a subnet range? say I have
the IP

10.10.0.0 and a subnet of 255.255.0.0 and am given the IP 10.10.50.1 and
want to verify that it is in that range.. thanks!
If (Subnet And SubnetMask) = (IpAddress And SubnetMask)
' Ip Address is in the subnet
End If

I don't know if there is a .NET class method that will do this.
Aug 28 '07 #2
On 28 Aug, 04:28, "Smokey Grindel" <nos...@nospam.comwrote:
Is there a way to check if an IP address is in a subnet range? say I have
the IP

10.10.0.0 and a subnet of 255.255.0.0 and am given the IP 10.10.50.1 and
want to verify that it is in that range.. thanks!
If you have the network address (10.10.0.0) and you have the subnet
mask (255.255.0.0) of the IP and the IP (10.10.50.1) itself you can
use the subnet to determine the network address of the IP and then
compare it to your real value to ensure it is correct.

dim ip as UInt32 = 168440321 'uint32 value for 10.10.50.1
dim subnet as UInt32 = 4294901760 'uint32 value for 255.255.0.0
dim network as UInt32 = 168427520 'uint32 value for 10.10.0.0

if ((ip And subnetMask) = networkAddress) then
'in range
else
'out of range
end if

Please be aware that Jack Jacksons reply is inaccurate. There is no
need to do the:

If (Subnet and SubnetMask) part of the IF, because the operation
(subnet And SubnetMask) will always equal subnet. It's a redundant
statement.

--

Phillip Taylor

Aug 28 '07 #3
On 28 Aug, 13:38, Phillip Taylor <Phillip.Ross.Tay...@gmail.com>
wrote:
On 28 Aug, 04:28, "Smokey Grindel" <nos...@nospam.comwrote:
Is there a way to check if an IP address is in a subnet range? say I have
the IP
10.10.0.0 and a subnet of 255.255.0.0 and am given the IP 10.10.50.1 and
want to verify that it is in that range.. thanks!

If you have the network address (10.10.0.0) and you have the subnet
mask (255.255.0.0) of the IP and the IP (10.10.50.1) itself you can
use the subnet to determine the network address of the IP and then
compare it to your real value to ensure it is correct.

dim ip as UInt32 = 168440321 'uint32 value for 10.10.50.1
dim subnetMask as UInt32 = 4294901760 'uint32 value for 255.255.0.0 ***********
dim networkAddress as UInt32 = 168427520 'uint32 value for 10.10.0.0 ***********

if ((ip And subnetMask) = networkAddress) then
'in range
else
'out of range
end if

Please be aware that Jack Jacksons reply is inaccurate. There is no
need to do the:

If (Subnet and SubnetMask) part of the IF, because the operation
(subnet And SubnetMask) will always equal subnet. It's a redundant
statement.

--

Phillip Taylor
Sorry, just fixed the variable names which were wrong.

Aug 28 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Stephen Biggs | last post by:
Given this code: void f(void){} int main(void){return (int)f+5;} Is there anything wrong with this in terms of the standards? Is this legal C code? One compiler I'm working with compiles this...
17
by: Zach | last post by:
#include <stdio.h> #include <math.h> int i=0, j=0, *z=0; double tanjent=0.0; void main(int *) { for(;;)
1
by: illegal.prime | last post by:
Hey all, I have an app, that could take two numbers of any type of numerical type int, long, double, float, uint, ulong, etc. I want to check that the numbers are part of a range that I consider...
6
by: minnesøtti | last post by:
Hi there, I am posting to a web-based forum which runs on ASP and uses JavaScript. I post via a proxy-server which rewrites JavaScript, does not send cookies back to the forum server, and which...
3
by: Shyckymn | last post by:
Dudes, How can I make a GROUP BY function into an SQL instruction, to count how much machines by ip address range (until the 3rd range)? Ex: (Existent registers for a field called ip_addr) ...
14
by: NetworkElf | last post by:
Hi all, Does anyone have some code that shows an example of how to loop through a range of IP addresses? I'm using text boxes to get a start and end value for the range. I was thinking about...
6
by: Nicolas Noakes | last post by:
Hello, I would like to convert to following process to code. Any advice is welcome. I have a hardware device which requires the this procedure to set it's IP address. First create an static...
4
by: Aaryan123 | last post by:
Function to check a number between a range in perl ========================================= Back ground: This situation has been fixed in Perl5.005. Use of .. in a for loop will iterate over...
36
by: Julienne Walker | last post by:
Ignoring implementation details and strictly following the C99 standard in terms of semantics, is there anything fundamentally flawed with describing the use of a (non-inline) function as an...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.