netaddr / netaddr

A network address manipulation library for Python

Home Page:https://netaddr.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IPNetwork().is_private() returning "True" for non private IPs

t3kl3ss opened this issue · comments

I have been using this module for a while and absolutely love it, I was just running through some subnetting today where I was trying to identify a bunch of private IPs inside our network and discovered there is a range of public IPs that come back as "True" when running the ".is_private()" check against the network.

I tested and validated this for 100.64.0.0/10. My initial run was against a /29 within one of those but am not willing to share that information for security. The other segments around that IP space seems perfectly fine for whatever reason though. Here's my output:

IPNetwork('100.64.0.0/8').is_private()
False
IPNetwork('100.64.0.0/10').is_private()
True
IPNetwork('100.128.0.0/10').is_private()
False

I tested in 2 environments:

  • netaddr v.0.7.19 on Python 3.6.9 on Ubuntu 18.04.5 LTS (Kernel: Linux 4.15.0-118-generic)
  • netaddr v.0.7.19 on Python 3.7.3 on MacOS 10.15.6 (Kernel 19.6.0)

After realizing I hadn't upgraded to netaddr 0.8.0, I updated, and tried again with the same results.

Nevermind, forgot this is carrier-grade NAT

So this is working all right after all?

So this is working all right after all?

Yup, working as it should - I dug more into the module after I posted to see if I could figure out what was causing that and realized it was working as intended (just didn't think about non-RFC1918 being private IPs). I just created my own IPSet() to include only RFC1918 IPs, as that is what I'm checking for in the script I'm writing.

It's more of an argumentative thing as far as the way it was built, but it's not exactly difficult to work around :)