So, I have this list of valid IP scopes, in the form below. How do I
match if $_SERVER[REMOTE_ADDR] is covered in any of these scopes?
193.11.120.0/21
193.11.128.0/24
193.11.129.0/24
193.11.130.0/24
193.11.131.0/24
First, I don't really know how to interprete the "/24" ending. I am
guessing that "193.11.131.0/24" means "193.11.131.X to 193.11.131.Y"
or something, but what? When that's translated to something useful,
how do I match IP numbers reliably?
Anyone done this?
--
Sandman[.net] 6 1767
Sandman said the following on 27/02/2006 19:59: So, I have this list of valid IP scopes, in the form below. How do I match if $_SERVER[REMOTE_ADDR] is covered in any of these scopes?
193.11.120.0/21 193.11.128.0/24 193.11.129.0/24 193.11.130.0/24 193.11.131.0/24
First, I don't really know how to interprete the "/24" ending. I am guessing that "193.11.131.0/24" means "193.11.131.X to 193.11.131.Y" or something, but what? When that's translated to something useful, how do I match IP numbers reliably?
The /XX represents the length of the subnet mask in bits, so your hunch
is pretty much correct.
An IP address matches a given network IP address if:
(Address ^ Mask) == (NetAddress ^ Mask)
where Mask = 11111...0000, the number of ones given by the /XX.
--
Oli
Oli Filth said the following on 27/02/2006 20:05: An IP address matches a given network IP address if:
(Address ^ Mask) == (NetAddress ^ Mask)
Oops, those should be &, not ^...
--
Oli
In article <mY*******************@newsfe6-win.ntli.net>,
Oli Filth <ca***@olifilth.co.uk> wrote: Sandman said the following on 27/02/2006 19:59: So, I have this list of valid IP scopes, in the form below. How do I match if $_SERVER[REMOTE_ADDR] is covered in any of these scopes?
193.11.120.0/21 193.11.128.0/24 193.11.129.0/24 193.11.130.0/24 193.11.131.0/24
First, I don't really know how to interprete the "/24" ending. I am guessing that "193.11.131.0/24" means "193.11.131.X to 193.11.131.Y" or something, but what? When that's translated to something useful, how do I match IP numbers reliably?
The /XX represents the length of the subnet mask in bits, so your hunch is pretty much correct.
An IP address matches a given network IP address if:
(Address ^ Mask) == (NetAddress ^ Mask)
where Mask = 11111...0000, the number of ones given by the /XX.
Ok, but how do I calculate it? Bits you say, but how do I translate 24
bits to addresses? For instance, the first line above, what addresses
does it cover?
--
Sandman[.net]
Sandman said the following on 27/02/2006 20:27: In article <mY*******************@newsfe6-win.ntli.net>, Oli Filth <ca***@olifilth.co.uk> wrote:
Sandman said the following on 27/02/2006 19:59: So, I have this list of valid IP scopes, in the form below. How do I match if $_SERVER[REMOTE_ADDR] is covered in any of these scopes?
193.11.120.0/21 193.11.128.0/24 193.11.129.0/24 193.11.130.0/24 193.11.131.0/24
First, I don't really know how to interprete the "/24" ending. I am guessing that "193.11.131.0/24" means "193.11.131.X to 193.11.131.Y" or something, but what? When that's translated to something useful, how do I match IP numbers reliably? The /XX represents the length of the subnet mask in bits, so your hunch is pretty much correct.
An IP address matches a given network IP address if:
(Address ^ Mask) == (NetAddress ^ Mask)
where Mask = 11111...0000, the number of ones given by the /XX.
Ok, but how do I calculate it? Bits you say, but how do I translate 24 bits to addresses? For instance, the first line above, what addresses does it cover?
An IP address is a 32-bit quantity, which can be represented as A.B.C.D,
where the actual 32-bit value is given by:
Y = (A * 2^24) + (B * 2^16) + (C * 2^8) + D
[I'm using ^ to represent "to the power of" in this case.]
So convert your test address and network address to this form, either
directly or by using the ip2long() function.
Then form your subnet mask as a 32-bit value.
[HINT: (2^X - 1) = (1000....000 - 1) = 111....111]
Then test the equality of the expression I originally posted, noting
that I got it wrong, and it should be:
(Address & Mask) == (NetAddress & Mask)
--
Oli
In article <Bu******************@newsfe2-win.ntli.net>,
Oli Filth <ca***@olifilth.co.uk> wrote: Sandman said the following on 27/02/2006 20:27: In article <mY*******************@newsfe6-win.ntli.net>, Oli Filth <ca***@olifilth.co.uk> wrote:
Sandman said the following on 27/02/2006 19:59: So, I have this list of valid IP scopes, in the form below. How do I match if $_SERVER[REMOTE_ADDR] is covered in any of these scopes?
193.11.120.0/21 193.11.128.0/24 193.11.129.0/24 193.11.130.0/24 193.11.131.0/24
First, I don't really know how to interprete the "/24" ending. I am guessing that "193.11.131.0/24" means "193.11.131.X to 193.11.131.Y" or something, but what? When that's translated to something useful, how do I match IP numbers reliably? The /XX represents the length of the subnet mask in bits, so your hunch is pretty much correct.
An IP address matches a given network IP address if:
(Address ^ Mask) == (NetAddress ^ Mask)
where Mask = 11111...0000, the number of ones given by the /XX.
Ok, but how do I calculate it? Bits you say, but how do I translate 24 bits to addresses? For instance, the first line above, what addresses does it cover?
An IP address is a 32-bit quantity, which can be represented as A.B.C.D, where the actual 32-bit value is given by:
Y = (A * 2^24) + (B * 2^16) + (C * 2^8) + D
[I'm using ^ to represent "to the power of" in this case.]
So convert your test address and network address to this form, either directly or by using the ip2long() function.
Then form your subnet mask as a 32-bit value. [HINT: (2^X - 1) = (1000....000 - 1) = 111....111]
Then test the equality of the expression I originally posted, noting that I got it wrong, and it should be:
(Address & Mask) == (NetAddress & Mask)
I get it now, I think I have it working. Thanks!
--
Sandman[.net] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Miki Tebeka |
last post by:
Hello,
Can anyone explain why:
>>> def make_inc(n):
s = n
def inc(i):
s += i
return s
return inc
|
by: Nils Grimsmo |
last post by:
hi,
i'm having some trouble nesting functions. consider the following:
def h():
x = 1
def g():
print x # ok, x is taken from h
g()
|
by: Dave Benjamin |
last post by:
I ran into an odd little edge case while experimenting with functions that
create classes on the fly (don't ask me why):
>>> def f(x):
... class C(object):
... x = x
... print C.x
......
|
by: kj |
last post by:
I'm a Perlhead (there, I said it). Years ago I made a genuine
attempt to learn Python, but my intense disappointed with the way
Python deals with scopes ultimately sapped my enthusiasm. I...
|
by: Armin Wagenknecht |
last post by:
Hello,
i am modelling a TopicMap, and I have the following problem:
I want to use two scopes in the topicmap for one occurence which has
to satsify BOTH scopes!!
Example:
I have the...
|
by: __PPS__ |
last post by:
Hello everybody,
in my exam in c++ I answered that destructors may be declared private,
public or protected.
The question was: "What possible scopes (public or private) can a
destructor have?"
...
|
by: Tim N. van der Leeuw |
last post by:
Hi,
The following might be documented somewhere, but it hit me unexpectedly
and I couldn't exactly find this in the manual either.
Problem is, that I cannot use augmented assignment operators...
|
by: giblfiz |
last post by:
I was hoping that someone on the group might have an idea of how to
access scopes (or symbol tables) other than the one you are currently
running in. (and no I don't mean global)
In particular,...
|
by: sora |
last post by:
Hi,
I've developed a MFC program under VS 6.0. My debugger *was* working fine and I've used it often for my project. Then, one day, the errors below appear and they prevent me from using the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
| |