Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange subnet calculations #4

Closed
Michuelnik opened this issue Jan 22, 2012 · 2 comments
Closed

Strange subnet calculations #4

Michuelnik opened this issue Jan 22, 2012 · 2 comments
Assignees
Milestone

Comments

@Michuelnik
Copy link
Collaborator

I think you are doing strange calculations. (You aren't doing things with binary (and,or,xor) operations?)
The three following examples are plain wrong.

Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import ipcalc
ipcalc.version
'0.5'
from ipcalc import Network
n = Network("129.0.0.0/2")
"128.0.0.0" in n
False
n.in_network("128.0.0.1")
False
"192.0.0.0" in n
True

@Michuelnik
Copy link
Collaborator Author

You aren't doing network calculations based upon the network address, but upon the representative the network is generated from.
This is a hack, which fixes the issues above. A cleaner solution would be to "normalize" the network address upon generation. This would be cleaner, for comparison, also. (e.g. Network("0.0.0.1/24") == Network("0.0.0.2/24")) This does not seem to be supported atm.

--- ipcalc.py   2011-12-20 12:34:35.000000000 +0100
+++ ipcalc-new.py   2012-01-22 17:32:42.000000000 +0100
@@ -499,7 +499,7 @@
         Check if the given IP address is within this network.
         '''
         other = Network(other)
-        return long(other) >= long(self) and long(other) < long(self) + self.size() - other.size() + 1
+        return long(other) >= long(self.network()) and long(other) < long(self.network()) + self.size() - other.size() + 1

     def __contains__(self, ip):
         '''

@tehmaze
Copy link
Owner

tehmaze commented Mar 27, 2012

Some form of normalisation is definately required, will be looking at this shortly,

@ghost ghost assigned tehmaze Mar 27, 2012
@tehmaze tehmaze closed this as completed Sep 7, 2012
@oSquat oSquat mentioned this issue Feb 8, 2013
tehmaze added a commit that referenced this issue Oct 20, 2013
Fixing bug #4 and #19, new function check_collision
skion pushed a commit to skion/ipcalc that referenced this issue Apr 24, 2014
tehmaze#19
tehmaze#4

The return is now better to read. The rule for detecting if an IP
address is within the network is:
Address <= Testing IP <= Broadcast

This function has only the ability to check an IP address by assuming
the netmask as /32 (IPv4) or /128 (Ipv6). If the tested IP has a
netmask greater than our network it will probably fail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants