Open braindevices opened 7 years ago
ipwhois.asn.ASNOrigin pulls routes and other info already: https://ipwhois.readthedocs.io/en/latest/ASN.html#asn-origin-usage-examples
Correct me if I'm wrong, but !g just returns the same routes, but without all the other information.
Thanks @secynic ! Yes it can get the response. However, I found several issues in current project.
The ASN origin lookup does not require any IP or network parameter. Thus the ASNOrigin should not require this. However, in current code, we have to initiate an ASNOrigin object by passing a Net object. It can be any Net object which is completely irrelevant to target ASN. So it is very confusing. The only reason, that the current code has it, is because it requires several member methods from Net class.
As we said before the ASN lookup has nothing to do with IP/network, thus the get_asn_origin_whois and get_htp_raw should not located in net.py as member methods. The only resources shared in Net class is timeout and the proxy_opener, which can easily be passed as arguments.
Since the only shared member in ASNOrigin class is the useless/unwanted Net object. After we move the needed functions out, we can avoid define the ASNOrigin as class. The entire thing will be much more clear.
One would expect avoiding
http
method if thewhois
method works. However, the current code repeats the lookup query withget_http_raw()
. Thus it slows down the process dramatically (normally 2-4 times slower than oswhois
command)
Here is my test results before and after my modification. #199 may fix these problems.
Thanks for the feedback, see my responses below.
You are absoultely right, and I agree that it is confusing (for now). I did this as a quick new feature prior to 1.0.0; this was to avoid delaying the release, which I expedited due to several bugs. The plan is to create a base class for proxy support, but I didn't implement this for that release due to pending changes in #153.
I decided a while ago to group all functions that perform network queries in a single location. I don't plan to change the file for these. I do, however, plan to break out any non-object dependant functions from the Net class.
I made this a class with future growth under consideration. I agree that its current state does not benefit from being a class.
Let me look into this one as a potential bug.
I can't accept your pull request for the following reasons:
On a similar note, I want to be able to take any ASN and find its country without having to specify an IP address or network. Is there a way to do this in the current version of ipwhois?
@ZaneHintzman Not currently. I know you can get this data via Cymru ASN lookups. Marking this as an enhancement.
I wonder is there any function I can use to obtain routes with specified origin. It should has the similar results as the
!g
option, for exmapleIt is preferred to return a list of ipaddress network objects or at least a list of CIDRs instead of just plain text.