473,797 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 13463
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.T ay...@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
1798
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 quietly, even with the most stringent and pedantic ANSI and warning levels, but generates code that only loads the address of "f" and fails to make the addition before returning a value from "main".
17
1409
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
2451
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 "valid". For my circumstances, I don't consider float.PositiveInfinity valid, nor do I consider the two numbers valid if the second number is smaller than the first. In other words, I want to check that the range is valid. I notice that while...
6
2766
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 changes its IP address every few minutes within the whole class A network. The moderator says he banned my IP address (let's put the moral issues of it aside for the sake of the technical discussion). This means he banned the whole network of...
3
1955
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) 172.17.17.1 172.17.17.2 172.17.17.3 172.18.196.12
14
6021
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 using 4 nested for-next loops, but I seem to be having trouble working out the logic to validate the octets in the beginning and ending address so the range works correctly. i.e. 172.16.1.1/172.20.1.1 should loop 172-172,16-20,1-254,1-254...
6
7053
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 ARP entry for the device's MAC address and the desired IP address. Then telnet to this IP address on TCP port 1. This will set the device to temporarily respond to that IP address. Now you can use HTTP to access the device's web interface and
4
8371
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 the range, without creating the entire range. for my $i (5 .. 500_005) { push(@results, some_func($i)); }
36
3400
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 address? I keep feeling like I'm missing something obvious. -Jul To keep things in context, this is in reference to describing functions to a beginner.
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9536
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10245
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5458
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.