Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

IPv6 and IPv4 address hex/octects that are 0 fail without the "<=" operator. #11

Closed
wants to merge 2 commits into from

3 participants

@twinshadow

Verified with the IPv6 address example in the README file.

>>> subnet = ipcalc.Network('2001:beef:babe::/48')
Traceback (most recent call last):
  File "", line 1, in 
  File "ipcalc.py", line 163, in __init__
    self.ip = self._dqtoi(ip)
  File "ipcalc.py", line 289, in _dqtoi
    raise ValueError, "%r: IPv6 address invalid: hextets should be between 0x0000 and 0xffff" % dq
ValueError: '2001:beef:babe::': IPv6 address invalid: hextets should be between 0x0000 and 0xffff

>>> subnet = ipcalc.Network('127.0.0.1/8')
Traceback (most recent call last):
  File "", line 1, in 
  File "ipcalc.py", line 163, in __init__
    self.ip = self._dqtoi(ip)
  File "ipcalc.py", line 306, in _dqtoi
    raise ValueError, "%r: IPv4 address invalid: bytes should be between 0 and 255" % dq
ValueError: '127.0.0.1': IPv4 address invalid: bytes should be between 0 and 255
@mattbennett

This still doesn't allow hex/octet values at the top of the range. I've created another pull request here: #12

@tehmaze tehmaze closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 30, 2012
  1. @twinshadow

    IPv6 address hextets that are 0 fail without the "<=" operator. Verif…

    twinshadow authored
    …ied with the IPv6 address example.
Commits on May 31, 2012
  1. @twinshadow
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 2 deletions.
  1. +2 −2 src/ipcalc.py
View
4 src/ipcalc.py
@@ -285,7 +285,7 @@ def _dqtoi(self, dq):
for h in hx:
if len(h) < 4:
h = '%04x' % int(h, 16)
- if not 0 < int(h, 16) < 0xffff:
+ if not 0 <= int(h, 16) < 0xffff:
raise ValueError, "%r: IPv6 address invalid: hextets should be between 0x0000 and 0xffff" % dq
ip += h
self.v = 6
@@ -302,7 +302,7 @@ def _dqtoi(self, dq):
if len(q) > 4:
raise ValueError, "%r: IPv4 address invalid: more than 4 bytes" % dq
for x in q:
- if not 0 < int(x) < 255:
+ if not 0 <= int(x) < 255:
raise ValueError, "%r: IPv4 address invalid: bytes should be between 0 and 255" % dq
while len(q) < 4:
q.insert(1, '0')
Something went wrong with that request. Please try again.