Coder Social home page Coder Social logo

simple_cidr's Introduction

simple_cidr

A simple lightweight IPv4 CIDR address toolbox

Small and fast IPv4 network address tool (75% faster then netaddr)

For cases where netaddr is too slow and you do not need the kitchen sink

To use:

       from simple_cidr import *

-or-

       just copy the functions you need into your code...

Example code

from simple_cidr import ip2int, cidr2int, ip_in_cidr, _ip_in_cidr

local_cidr = "10.1.10.0/21"
test_ip_list = [
    '1.183.157.52', '59.152.13.85', '132.255.253.243', '1.54.12.112',
    '91.93.164.13', '23.94.184.55', '52.2.45.42', '10.1.13.244',
    '31.163.95.153', '10.1.11.1', '103.60.220.87', '10.1.10.55'
]

my_cidr = cidr2int(local_cidr)

for ip in test_ip_list:
    if ip_in_cidr(ip, my_cidr):
        print ip, "\tis local"
    else:
        print ip, "\tis non-local"

written: Peter Shipley

https://github.com/evilpete/simple_cidr

Sun Dec 16 20:11:53 PST 2018

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.