Project

General

Profile

Actions

Bug #7676

closed

Searching for IPv6 addresses is not working

Added by Rajmund Hruška over 1 year ago. Updated 10 months ago.

Status:
Closed
Priority:
Normal
Category:
Development - GUI
Target version:
Start date:
08/24/2023
Due date:
% Done:

100%

Estimated time:
To be discussed:
No

Description

Actions #1

Updated by Rajmund Hruška about 1 year ago

  • Status changed from New to In Progress

The issue is in the underlying ipranges library.

When searching for network in the networks module, the input is converted to IP object from ipranges so that it would be possible to search for supersets. The change was introduced in dd0502fd (I am really glad I put those comments there ).

Anyway, the following code in ipranges:

def ip_from_str(s):
    for t in IP4, IP6:
        try:
            return t(s)
        except ValueError:
            pass
    raise ValueError("%s does not appear as IPv4 nor IPv6 address" % s)

tries to convert first to IPv4 address, but this produces the following type of error for IPv6 addresses:

>>> ipranges.ip_from_str(42540632040320178)
Traceback (most recent call last):
  File "/var/mentat/venv/lib/python3.7/site-packages/ipranges.py", line 188, in ip4_to_str
    return socket.inet_ntop(socket.AF_INET, struct.pack('!L', i))
struct.error: 'L' format requires 0 <= number <= 4294967295

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/mentat/venv/lib/python3.7/site-packages/ipranges.py", line 55, in __repr__
    return "%s('%s')" % (type(self).__name__, str(self))
  File "/var/mentat/venv/lib/python3.7/site-packages/ipranges.py", line 169, in __str__
    def __str__(self): return self.to_str(self.ip)
  File "/var/mentat/venv/lib/python3.7/site-packages/ipranges.py", line 190, in ip4_to_str
    raise ValueError("Unable to convert to IPv6 address: %s" % i)
ValueError: Unable to convert to IPv6 address: 42540632040320178

Actions #2

Updated by Rajmund Hruška 11 months ago

  • Status changed from In Progress to Resolved
  • Assignee set to Rajmund Hruška
  • % Done changed from 0 to 100

This

Rajmund Hruska wrote in #note-1:

The issue is in the underlying ipranges library.

When searching for network in the networks module, the input is converted to IP object from ipranges so that it would be possible to search for supersets. The change was introduced in dd0502fd (I am really glad I put those comments there ).

Anyway, the following code in ipranges:
[...]

tries to convert first to IPv4 address, but this produces the following type of error for IPv6 addresses:
[...]

This is actually not an issue but rather breaking a contract from my side. The function I used is expecting a string but I provide integers.

Actions #3

Updated by Rajmund Hruška 11 months ago

  • Status changed from Resolved to In Review
Actions #4

Updated by Rajmund Hruška 10 months ago

  • Status changed from In Review to Closed
Actions

Also available in: Atom PDF