Giter VIP home page Giter VIP logo

Comments (4)

timmc avatar timmc commented on August 23, 2024

I have a fix locally along with some tests:

MAX_IP = int(ipaddress.IPv4Address('255.255.255.255'))

def traverse_expander(ip, n=5):
    class_c = get_class_c_network(ip)

    ip_min = max(int(ip) - n, 0)
    ip_max = min(int(ip) + n, MAX_IP)
    result = [ipaddress.IPv4Address(i) for i in range(ip_min, ip_max + 1)]
    result = [i for i in result if i in class_c]

    return result

...but it occurs to me that the class-bounding is a little redundant with the other min/max stuff and they could be combined. However, IPv4Address doesn't seem to have any convenient "take this apart into octets" so I'll need to poke at this a bit longer.

from fierce.

mschwager avatar mschwager commented on August 23, 2024

Your fix looks sane to me! One suggestion I have would be to just constant-ify the max IP - using ipaddress.IPv4Address seems like unnecessary overhead. Something like:

def traverse_expander(ip, n=5):
    class_c = get_class_c_network(ip)

    ip = int(ip)
    ipv4_min = 0
    ipv4_max = 2**32 - 1
    ip_min = max(ip - n, ipv4_min)
    ip_max = min(ip + n, ipv4_max)

    result = [ipaddress.IPv4Address(i) for i in range(ip_min, ip_max + 1)]
    result = [i for i in result if i in class_c]

    return result

it occurs to me that the class-bounding is a little redundant with the other min/max stuff and they could be combined.

Not entirely sure what you're getting at here, but this solution LGTM!

from fierce.

timmc avatar timmc commented on August 23, 2024

Re: the class-bounding, this is probably just bikeshedding, but I was noticing that the filtering IPs by whether they're in the same class C could be accomplished at the same time as the bounds check filtering by just setting the ip_min and ip_max to the lowest and highest of the class C (rather than the lowest and highest of all IPv4 addresses.) A little math oughtta do it. :-)

from fierce.

mschwager avatar mschwager commented on August 23, 2024

Heads up @timmc, I just released version 1.3.0 (https://pypi.org/project/fierce/1.3.0/) which includes your changes. Thanks again!

from fierce.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.