Bug #7676
closedSearching for IPv6 addresses is not working
100%
Description
The IPv6 address can be found by using "Search local WHOIS": https://mentat-alt.cesnet.cz/mentat/whois/search?search=2001%3A718%3A1%3Aa100%3A%3A161%3A43&submit=Search
But no result is found when searching in the "Network management": https://mentat-alt.cesnet.cz/mentat/networks/list?search=2001%3A718%3A1%3Aa100%3A%3A161%3A43&submit=Search
Updated by Rajmund Hruška 10 months 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
Updated by Rajmund Hruška 7 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.
Updated by Rajmund Hruška 7 months ago
- Status changed from Resolved to In Review