473,785 Members | 2,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

determine if 2 IP's are on the same subnet?

I'm looking for a function to return true/false depending on if two supplied
IP's (as strings) are in the same subnet (also supplied).
Im getting nowhere fast unfortunately - I know the theory behind it, but I
have no idea on how to actually implement it!
I have split my supplied 3 IP's into 4 numbers each, but past that I'm
stuck - on paper I would convert them to binary and write down all the 1's
and 0's then figure it out, but in code...?
Thanks
James
Nov 21 '05 #1
1 2420
You need to use the "and" function between each of the 4 octects in the ip
and the equilavalent octect in the net mask to get the "network" address.
If the network address is the same for the two ip's then they are the same
network.

Hope this helps..

Regards
Simon

"JamesB" <ja***@spamblow s.puffle.co.uk> wrote in message
news:43******** *************** @news.zen.co.uk ...
I'm looking for a function to return true/false depending on if two
supplied IP's (as strings) are in the same subnet (also supplied).
Im getting nowhere fast unfortunately - I know the theory behind it, but I
have no idea on how to actually implement it!
I have split my supplied 3 IP's into 4 numbers each, but past that I'm
stuck - on paper I would convert them to binary and write down all the 1's
and 0's then figure it out, but in code...?
Thanks
James

Nov 21 '05 #2

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

Similar topics

4
3737
by: Dan | last post by:
Does anybody know how to control the source IP address (IPv4) when using the urllib2 library? I have a Linux box with several IP addresses in the same subnet, and I want to simulate several individuals within that subnet accessing web pages independently. I need the functionality of urllib2 because there will be redirects and other HTTP-type functions to implement. It would be nice if I could create (and bind) sockets myself and then...
2
10247
by: Manoj Nair | last post by:
Hi, Is there a way by which the IP address of a terminal can be set through code. thanks in advance Manoj
19
1538
by: Frederik | last post by:
Hi all, Situation: - 2 computers behind router/switch; - dhcp enabled on router; - computer name 1 = cpuA (WinXP Pro); - computer name 2 = cpuB (WinXP Home); - cpuA and cpuB can access each other's resources; - cpuA runs IIS with asp.net website; - cpuA and cpuB are in the same workgroup and have
3
6111
by: billie | last post by:
Hi all. I'm searching for a module that permits me to low-level interact with ethernet interfaces of my system. I would like to determine at least the first of the followings values: 1 - IP address assigned to the interface 2 - subnet mask 3 - default gateway 4 - primary and secondary dns 5 - default wins server 6 - mac address
20
1572
by: Terry Olsen | last post by:
I'm writing an app that communicates with computers both inside and outside my router. So I need to determine by the remote host's IP address if I need to send them my LAN IP or my Internet IP. Someone suggested AND'ing the IP and my Subnet Mask but I come up with this: My IP: 192.168.0.14 Mask: 255.255.255.0 Result: 192.168.0.0
9
2417
by: =?Utf-8?B?SG93YXJkIFNtaXRo?= | last post by:
I am using VC++ 6.0 (with SP5 installed). When using WinXP this is with SP2 installed. I am developing an instrumentation system comprising a set of networked PCs connected using TCP/IP TCP links. Communications on the Windows PCs use a class derived from CAsyncSocket(). I have written client and server versions of my software for use on the appropriate PCs. I am also using communicating with a legacy DOS based system, with the software...
3
13461
by: Smokey Grindel | last post by:
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!
2
3106
by: nussu | last post by:
Hi , I need to find a subnet mask number for a given IP Address number. I have two textbox's once enter the ip address in first textbox i need to get subnet mask number for that ip address in second textbox. Please help me by providing links or c#.net code. Thanks in Advance. Regards, Nussu
1
2145
by: =?Utf-8?B?Q2FybG9z?= | last post by:
Guys, I have a little problem here. I have an AD domain with one DC and 2 other member servers and when I go to My Network Places and browse the network, I can seamless see a list of all workstations (my 2 member servers and my single DC) and servers. The network IP is 10.10.10.0/24 I have a second VLAN, 10.10.20.0/24 where I have another member server. I joined this member server to the domain, added a subnet in AD Sites and Services...
0
9647
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
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
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...
1
10100
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
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...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
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...
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.