hadiasghari / pyasn

Python IP address to Autonomous System Number lookup module. (Supports fast local lookups, and historical lookups using archived BGP dumps.)
Other
292 stars 72 forks source link

Modify lookup to allow network matching #41

Closed jmanteau closed 7 years ago

jmanteau commented 7 years ago

I'll try to do some tests later to finalize this

hadiasghari commented 7 years ago

Hi @jmanteau , can you tell me a bit about this change? What is an example use case? Thanks!

jmanteau commented 7 years ago

Hello,

My use case is that I'm comparing an internal network which use extensively public IPv4 adress spaces to the "correct" network and the AS corresponding to it.

However I think that the possibility to add network matching instead of only IP can be useful for a broader scope as well.

hadiasghari commented 7 years ago

@jmanteau I don't fully understand, could you elaborate your use-case with examples. What do you mean by "correct"? What would be "incorrect"?

jmanteau commented 7 years ago

I have a client where the interal routing space has no default route and internal subnet are overlapping public address space. The need is to introduce the default route. For example, let's say that internally the 40.0.0.0/24 is used. I want to match this network to the https://bgpview.io/prefix/40.0.0.0/19 So I loop over the internal client subnet, I do the matching with this patch and at the end I have this file (already produced as I've done the patching locally)

| Internal Subnet | Matching Prefix | AS Number | AS Name  |
|-----------------|-----------------|-----------|----------|
| 40.0.0.0/24     | 40.0.0.0/19     | 4249      | LILLY-AS |
| Subnet B        | XXX             | 12345     | ABCD     |
| Subnet C        | None            | None      | None     |
jmanteau commented 7 years ago

Hello, Are you interested in more feedback/ push requests ? For example I missed a function get_all_asn() on pyasn. Easy to do with [ x.asn for x in dbasn.radix.nodes() ] but not present by default.

hadiasghari commented 7 years ago

@jmanteau thank you for the ideas. I thought about them, and IMO they don't fit with pyasn's main goal, which is to enable fast historical IP-to-ASN lookups. The two use cases you mention are rather specific cases.

We exposed the underlying radix-tree to enable such cases when needed, but not add them to the library. I will thus close this request without a merge. And yes, I am always interested in feedback and pull requests!

jmanteau commented 7 years ago

OK. Fine for me. I have adjusted my code in consequence to use directly the radix tree. Last thing I have implemented is the search_covered. But for that I have reused the py-radix library. I wanted for a given /16 know which subnets included in it are announced.