Closed svaningelgem closed 9 months ago
Thanks for the report @MaurUppi! I've never had a better bughunter than you ;-).
I'll look into it and see why this behaves that way.
Thanks for the report @MaurUppi! I've never had a better bughunter than you ;-).
I'll look into it and see why this behaves that way.
I'm sharing one more example with you. This case differs from others cause this IP should be in a reserved IP range.
100.64.0.0-100.127.255.255, DBIP_ZZ, IP2LOCATION_-, IPInfo_
Let me explain to you.
ZZ
and -
mean Reserved in their Country databases and IPinfo Country database has not even stored it. The IP2Location will display the "-" in country field when the IP address range is still unallocated to any countries. It is also known as reserved IP address range.
For this case, I think you can output No such record
or You're checking reserved IP address
127.0.0.0-127.255.255.255, DBIP_ZZ, IP2LOCATION_-, IPInfo_
224.0.0.0-255.255.255.255, DBIP_ZZ, IP2LOCATION_-, IPInfo_
100.64.0.0-100.127.255.255, DBIP_ZZ, IP2LOCATION_-, IPInfo_
172.16.0.0-172.31.255.255, DBIP_ZZ, IP2LOCATION_-, IPInfo_
0.0.0.0-0.255.255.255, DBIP_ZZ, IP2LOCATION_-, IPInfo_
192.88.99.0-192.88.99.255, DBIP_ZZ, IP2LOCATION_-, IPInfo_
192.168.0.0-192.168.255.255, DBIP_ZZ, IP2LOCATION_-, IPInfo_
169.254.0.0-169.254.255.255, DBIP_ZZ, IP2LOCATION_-, IPInfo_
10.0.0.0-10.255.255.255, DBIP_ZZ, IP2LOCATION_-, IPInfo_
198.18.0.0-198.19.255.255, DBIP_ZZ, IP2LOCATION_-, IPInfo_
PS D:\Github\location_ipfire_db_reader\location_ipfire_db_reader> python.exe .\ip_location_script.py 100.127.255.25
Traceback (most recent call last):
File "D:\Github\location_ipfire_db_reader\location_ipfire_db_reader\ip_location_script.py", line 31, in <module>
main(ip_address)
File "D:\Github\location_ipfire_db_reader\location_ipfire_db_reader\ip_location_script.py", line 6, in main
ip_info = db[ip_address]
~~^^^^^^^^^^^^
File "C:\Users\nucrpl\AppData\Local\Programs\Python\Python312\Lib\site-packages\location_ipfire_db_reader\database.py", line 14, in __getitem__
return IpInformation(self, ip, *self._find_network_information(ip))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\nucrpl\AppData\Local\Programs\Python\Python312\Lib\site-packages\location_ipfire_db_reader\database_reader.py", line 132, in _find_network_information
raise ValueError("Cannot find anything anymore!")
ValueError: Cannot find anything anymore!
Thanks, I implemented some better exceptions in these cases. And adjusted the README in this way:
Exceptions
All exceptions within this package will inherit from
LocationIPFireDBReaderException
. So if you want a blanket-capture-all. That's what you'll need.However, these are more fine-tuned versions:
UnknownASNName
: will be raised when an ASN is found, but there is no known name for it.IPAddressError
: will be raised when an IP lookup fails. This happens with reserved IPs so far.
So these will be thrown instead of the ValueError
s before.
I am doubting a little bit if I should just return an empty value instead of an exception though?
I think the below two are similar to 201.148.95.249
case.
http://ip-api.com/csv/88.218.67.25
success,United Kingdom,GB,ENG,England,London,W1B,51.5074,-0.127758,Europe/London,TrafficTransitSolution LLC,TrafficTransitSolution LLC,,88.218.67.25
PS D:\Github\location_ipfire_db_reader\location_ipfire_db_reader> python.exe .\ip_location_script.py 88.218.67.25
Traceback (most recent call last):
File "D:\Github\location_ipfire_db_reader\location_ipfire_db_reader\ip_location_script.py", line 31, in <module>
main(ip_address)
File "D:\Github\location_ipfire_db_reader\location_ipfire_db_reader\ip_location_script.py", line 14, in main
ASN Name: {ip_info.asn_name}
^^^^^^^^^^^^^^^^
File "C:\Users\nucrpl\AppData\Local\Programs\Python\Python312\Lib\functools.py", line 995, in __get__
val = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\nucrpl\AppData\Local\Programs\Python\Python312\Lib\site-packages\location_ipfire_db_reader\ip_information.py", line 95, in asn_name
obj = self._find_object(
^^^^^^^^^^^^^^^^^^
File "C:\Users\nucrpl\AppData\Local\Programs\Python\Python312\Lib\site-packages\location_ipfire_db_reader\ip_information.py", line 84, in _find_object
raise ValueError(f"Can't find asn object with id {self.asn}!")
ValueError: Can't find asn object with id 0!
http://ip-api.com/csv/202.37.126.25
success,New Zealand,NZ,HKB,Hawke's Bay,Napier City,4143,-39.5109,176.876,Pacific/Auckland,RUAWHARO,,,202.37.126.25
PS D:\Github\location_ipfire_db_reader\location_ipfire_db_reader> python.exe .\ip_location_script.py 202.37.126.25
Traceback (most recent call last):
File "D:\Github\location_ipfire_db_reader\location_ipfire_db_reader\ip_location_script.py", line 31, in <module>
main(ip_address)
File "D:\Github\location_ipfire_db_reader\location_ipfire_db_reader\ip_location_script.py", line 14, in main
ASN Name: {ip_info.asn_name}
^^^^^^^^^^^^^^^^
File "C:\Users\nucrpl\AppData\Local\Programs\Python\Python312\Lib\functools.py", line 995, in __get__
val = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\nucrpl\AppData\Local\Programs\Python\Python312\Lib\site-packages\location_ipfire_db_reader\ip_information.py", line 95, in asn_name
obj = self._find_object(
^^^^^^^^^^^^^^^^^^
File "C:\Users\nucrpl\AppData\Local\Programs\Python\Python312\Lib\site-packages\location_ipfire_db_reader\ip_information.py", line 84, in _find_object
raise ValueError(f"Can't find asn object with id {self.asn}!")
ValueError: Can't find asn object with id 0!
It looks like ipfire hasn't all the information about these names (yet). I will submit a bug report to them with the ones they are missing and hopefully it'll be incorporated soon(ish).
Please find the bug report here: Missing AS names
Now on to the "asn object id 0" part of your report: https://ipinfo.io/202.37.126.25 <-- here, no asn is known. Same for the other one. No as number is known.
What should I do here? Just return an empty value (0 for the number and ""
for the name)? Or simply raise the exception?
Please find the bug report here: Missing AS names
Now on to the "asn object id 0" part of your report: https://ipinfo.io/202.37.126.25 <-- here, no asn is known. Same for the other one. No as number is known.
What should I do here? Just return an empty value (0 for the number and
""
for the name)? Or simply raise the exception?
My idea is raise the executions OR simply output Empty msg.
such as:
ip: 8.8.8.8
subnet_mask: 24
network_address: 8.8.8.0
ip_with_cidr: 8.8.8.0/24
asn:
asn_name:
country_code: US
country_name: United States of America
country_continent: NA
is_anonymous_proxy: False
is_satellite_provider: False
is_anycast: True
is_drop: False
Thanks for your valuable input. I adjusted the sources now to have the ability to allow for no exceptions raised
What if you don't want exceptions?
If you don't like to handle exceptions, you can always initialize your
LocationDatabase
like this:db = LocationDatabase(raise_exceptions=False)
Now if for example the AS isn't known, it will output
0
for the asn, and""
for the AS name. Instead of raising an exception.
This is not yet in a release (PR #5 pending for that). But the effect will be somewhat like you mentioned.
However, for 8.8.8.8
, the asn is 15169
, and the asn will always return a number (as it stands for "autonomous system number").
it works as expected with some IPs!!!
But I'm not sure what happened with
201.148.95.249
http://ip-api.com/csv/201.148.95.249
_Originally posted by @MaurUppi in https://github.com/svaningelgem/location_ipfire_db_reader/issues/1#issuecomment-1903640126_