ipwhois icon indicating copy to clipboard operation
ipwhois copied to clipboard

Is there any way I can obtain routes with specified origin

Open braindevices opened this issue 7 years ago • 5 comments

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 exmaple

whois -h whois.radb.net '!gAS19679'.
A1761
108.160.160.0/21 108.160.160.0/20 108.160.160.0/22 108.160.160.0/23 108.160.160.0/24 108.160.161.0/24 108.160.162.0/23 108.160.162.0/24 108.160.163.0/24 108.160.164.0/22 108.160.164.0/23 108.160.164.0/24 108.160.165.0/24 108.160.166.0/23 108.160.166.0/24 108.160.167.0/24 108.160.168.0/21 108.160.168.0/22 108.160.168.0/23 108.160.168.0/24 108.160.169.0/24 108.160.170.0/23 108.160.170.0/24 108.160.171.0/24 108.160.172.0/22 108.160.172.0/23 108.160.172.0/24 108.160.173.0/24 108.160.174.0/23 108.160.174.0/24 108.160.175.0/24 199.47.216.0/22 199.47.216.0/23 199.47.216.0/24 199.47.217.0/24 199.47.218.0/23 199.47.218.0/24 199.47.219.0/24 45.58.72.0/21 45.58.68.0/22 45.58.72.0/22 45.58.76.0/22 45.58.68.0/23 45.58.70.0/23 45.58.72.0/23 45.58.74.0/23 45.58.76.0/23 45.58.78.0/23 45.58.66.0/24 45.58.67.0/24 45.58.68.0/24 45.58.69.0/24 45.58.70.0/24 45.58.71.0/24 45.58.72.0/24 45.58.73.0/24 45.58.74.0/24 45.58.75.0/24 45.58.76.0/24 45.58.77.0/24 45.58.78.0/24 45.58.79.0/24 185.45.9.0/24 185.45.10.0/23 185.45.10.0/24 185.45.11.0/24 162.125.16.0/20 162.125.17.0/24 162.125.0.0/16 162.125.18.0/24 162.125.4.0/24 162.125.0.0/18 162.125.32.0/20 162.125.32.0/24 162.125.64.0/20 162.125.80.0/20 162.125.0.0/24 162.125.1.0/24 162.125.2.0/24 162.125.3.0/24 162.125.5.0/24 162.125.6.0/24 162.125.19.0/24 162.125.33.0/24 162.125.34.0/24 162.125.48.0/20 185.45.8.0/22 162.125.48.0/24 162.125.49.0/24 162.125.64.0/21 162.125.64.0/24 162.125.65.0/24 162.125.66.0/24 162.125.80.0/24 162.125.81.0/24 162.125.82.0/24 162.125.72.0/21 162.125.88.0/21 162.125.80.0/21 162.125.86.0/24 162.125.16.0/24 162.125.248.0/24 199.47.217.64/26 45.58.64.0/20 45.58.64.0/21 45.58.64.0/22 45.58.64.0/23 45.58.64.0/24 45.58.65.0/24 45.58.66.0/23 162.125.7.0/24 162.125.8.0/24 162.125.83.0/24
C

It is preferred to return a list of ipaddress network objects or at least a list of CIDRs instead of just plain text.

braindevices avatar Aug 04 '17 09:08 braindevices

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.

secynic avatar Aug 04 '17 21:08 secynic

Thanks @secynic ! Yes it can get the response. However, I found several issues in current project.

  1. the ASNOrigin initiation should not require Net object

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.

  1. The ASN lookup related functions should not be in net.py at all.

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.

  1. The ASNOrigin may not be class at all.

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.

  1. successful query does not stop looping through all asn_methods

One would expect avoiding http method if the whois method works. However, the current code repeats the lookup query with get_http_raw(). Thus it slows down the process dramatically (normally 2-4 times slower than os whois command)

Here is my test results before and after my modification. #199 may fix these problems.

braindevices avatar Aug 06 '17 04:08 braindevices

Thanks for the feedback, see my responses below.

  1. 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.

  2. 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.

  3. I made this a class with future growth under consideration. I agree that its current state does not benefit from being a class.

  4. Let me look into this one as a potential bug.

I can't accept your pull request for the following reasons:

  • See my above responses regarding the code changes
  • I will not accept a request that modifies the license. I give recognition to contributors via the changelog, and substantial contributors in the readme.
  • Your Travis/tests failed
  • This project is now following GitFlow: https://ipwhois.readthedocs.io/en/latest/CONTRIBUTING.html#gitflow-model

secynic avatar Aug 25 '17 23:08 secynic

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 avatar May 23 '18 22:05 ZaneHintzman

@ZaneHintzman Not currently. I know you can get this data via Cymru ASN lookups. Marking this as an enhancement.

secynic avatar Oct 26 '18 02:10 secynic