Sheldon  Grant

Sheldon Grant

1652085928

Ipaddr.js: IP Address Manipulation Library in JavaScript

ipaddr.js — An IPv6 and IPv4 address manipulation library

ipaddr.js is a small (1.9K minified and gzipped) library for manipulating IP addresses in JavaScript environments. It runs on both CommonJS runtimes (e.g. nodejs) and in a web browser.

ipaddr.js allows you to verify and parse string representation of an IP address, match it against a CIDR range or range list, determine if it falls into some reserved ranges (examples include loopback and private ranges), and convert between IPv4 and IPv4-mapped IPv6 addresses.

Installation

npm install ipaddr.js

or

bower install ipaddr.js

Older Node support

Use 2.x release for nodejs versions 10+. Use the 1.x release for versions of nodejs older than 10.

API

ipaddr.js defines one object in the global scope: ipaddr. In CommonJS, it is exported from the module:

const ipaddr = require('ipaddr.js');

The API consists of several global methods and two classes: ipaddr.IPv6 and ipaddr.IPv4.

Global methods

There are three global methods defined: ipaddr.isValid, ipaddr.parse and ipaddr.process. All of them receive a string as a single parameter.

The ipaddr.isValid method returns true if the address is a valid IPv4 or IPv6 address, and false otherwise. It does not throw any exceptions.

The ipaddr.parse method returns an object representing the IP address, or throws an Error if the passed string is not a valid representation of an IP address.

The ipaddr.process method works just like the ipaddr.parse one, but it automatically converts IPv4-mapped IPv6 addresses to their IPv4 counterparts before returning. It is useful when you have a Node.js instance listening on an IPv6 socket, and the net.ivp6.bindv6only sysctl parameter (or its equivalent on non-Linux OS) is set to 0. In this case, you can accept IPv4 connections on your IPv6-only socket, but the remote address will be mangled. Use ipaddr.process method to automatically demangle it.

Object representation

Parsing methods return an object which descends from ipaddr.IPv6 or ipaddr.IPv4. These objects share some properties, but most of them differ.

Shared properties

One can determine the type of address by calling addr.kind(). It will return either "ipv6" or "ipv4".

An address can be converted back to its string representation with addr.toString(). Note that this method:

  • does not return the original string used to create the object (in fact, there is no way of getting that string)
  • returns a compact representation (when it is applicable)

A match(range, bits) method can be used to check if the address falls into a certain CIDR range. Note that an address can be (obviously) matched only against an address of the same type.

For example:

const addr  = ipaddr.parse('2001:db8:1234::1');
const range = ipaddr.parse('2001:db8::');

addr.match(range, 32); // => true

Alternatively, match can also be called as match([range, bits]). In this way, it can be used together with the parseCIDR(string) method, which parses an IP address together with a CIDR range.

For example:

const addr = ipaddr.parse('2001:db8:1234::1');

addr.match(ipaddr.parseCIDR('2001:db8::/32')); // => true

A range() method returns one of predefined names for several special ranges defined by IP protocols. The exact names (and their respective CIDR ranges) can be looked up in the source: IPv6 ranges and IPv4 ranges. Some common ones include "unicast" (the default one) and "reserved".

You can match against your own range list by using ipaddr.subnetMatch(address, rangeList, defaultName) method. It can work with a mix of IPv6 or IPv4 addresses, and accepts a name-to-subnet map as the range list. For example:

const rangeList = {
  documentationOnly: [ ipaddr.parse('2001:db8::'), 32 ],
  tunnelProviders: [
    [ ipaddr.parse('2001:470::'), 32 ], // he.net
    [ ipaddr.parse('2001:5c0::'), 32 ]  // freenet6
  ]
};
ipaddr.subnetMatch(ipaddr.parse('2001:470:8:66::1'), rangeList, 'unknown'); // => "tunnelProviders"

The addresses can be converted to their byte representation with toByteArray(). (Actually, JavaScript mostly does not know about byte buffers. They are emulated with arrays of numbers, each in range of 0..255.)

const bytes = ipaddr.parse('2a00:1450:8007::68').toByteArray(); // ipv6.google.com
bytes // => [42, 0x00, 0x14, 0x50, 0x80, 0x07, 0x00, <zeroes...>, 0x00, 0x68 ]

The ipaddr.IPv4 and ipaddr.IPv6 objects have some methods defined, too. All of them have the same interface for both protocols, and are similar to global methods.

ipaddr.IPvX.isValid(string) can be used to check if the string is a valid address for particular protocol, and ipaddr.IPvX.parse(string) is the error-throwing parser.

ipaddr.IPvX.isValid(string) uses the same format for parsing as the POSIX inet_ntoa function, which accepts unusual formats like 0xc0.168.1.1 or 0x10000000. The function ipaddr.IPv4.isValidFourPartDecimal(string) validates the IPv4 address and also ensures that it is written in four-part decimal format.

IPv6 properties

Sometimes you will want to convert IPv6 not to a compact string representation (with the :: substitution); the toNormalizedString() method will return an address where all zeroes are explicit.

For example:

const addr = ipaddr.parse('2001:0db8::0001');
addr.toString(); // => '2001:db8::1'
addr.toNormalizedString(); // => '2001:db8:0:0:0:0:0:1'

The isIPv4MappedAddress() method will return true if this address is an IPv4-mapped one, and toIPv4Address() will return an IPv4 object address.

To access the underlying binary representation of the address, use addr.parts.

const addr = ipaddr.parse('2001:db8:10::1234:DEAD');
addr.parts // => [0x2001, 0xdb8, 0x10, 0, 0, 0, 0x1234, 0xdead]

A IPv6 zone index can be accessed via addr.zoneId:

const addr = ipaddr.parse('2001:db8::%eth0');
addr.zoneId // => 'eth0'

IPv4 properties

toIPv4MappedAddress() will return a corresponding IPv4-mapped IPv6 address.

To access the underlying representation of the address, use addr.octets.

const addr = ipaddr.parse('192.168.1.1');
addr.octets // => [192, 168, 1, 1]

prefixLengthFromSubnetMask() will return a CIDR prefix length for a valid IPv4 netmask or null if the netmask is not valid.

ipaddr.IPv4.parse('255.255.255.240').prefixLengthFromSubnetMask() == 28
ipaddr.IPv4.parse('255.192.164.0').prefixLengthFromSubnetMask()  == null

subnetMaskFromPrefixLength() will return an IPv4 netmask for a valid CIDR prefix length.

ipaddr.IPv4.subnetMaskFromPrefixLength(24) == '255.255.255.0'
ipaddr.IPv4.subnetMaskFromPrefixLength(29) == '255.255.255.248'

broadcastAddressFromCIDR() will return the broadcast address for a given IPv4 interface and netmask in CIDR notation.

ipaddr.IPv4.broadcastAddressFromCIDR('172.0.0.1/24') == '172.0.0.255'

networkAddressFromCIDR() will return the network address for a given IPv4 interface and netmask in CIDR notation.

ipaddr.IPv4.networkAddressFromCIDR('172.0.0.1/24') == '172.0.0.0'

Conversion

IPv4 and IPv6 can be converted bidirectionally to and from network byte order (MSB) byte arrays.

The fromByteArray() method will take an array and create an appropriate IPv4 or IPv6 object if the input satisfies the requirements. For IPv4 it has to be an array of four 8-bit values, while for IPv6 it has to be an array of sixteen 8-bit values.

For example:

const addr = ipaddr.fromByteArray([0x7f, 0, 0, 1]);
addr.toString(); // => '127.0.0.1'

or

const addr = ipaddr.fromByteArray([0x20, 1, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
addr.toString(); // => '2001:db8::1'

Both objects also offer a toByteArray() method, which returns an array in network byte order (MSB).

For example:

const addr = ipaddr.parse('127.0.0.1');
addr.toByteArray(); // => [0x7f, 0, 0, 1]

or

const addr = ipaddr.parse('2001:db8::1');
addr.toByteArray(); // => [0x20, 1, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]

Author: Whitequark
Source Code: https://github.com/whitequark/ipaddr.js 
License: MIT license

#node #javascript #ip 

What is GEEK

Buddha Community

Ipaddr.js: IP Address Manipulation Library in JavaScript

NBB: Ad-hoc CLJS Scripting on Node.js

Nbb

Not babashka. Node.js babashka!?

Ad-hoc CLJS scripting on Node.js.

Status

Experimental. Please report issues here.

Goals and features

Nbb's main goal is to make it easy to get started with ad hoc CLJS scripting on Node.js.

Additional goals and features are:

  • Fast startup without relying on a custom version of Node.js.
  • Small artifact (current size is around 1.2MB).
  • First class macros.
  • Support building small TUI apps using Reagent.
  • Complement babashka with libraries from the Node.js ecosystem.

Requirements

Nbb requires Node.js v12 or newer.

How does this tool work?

CLJS code is evaluated through SCI, the same interpreter that powers babashka. Because SCI works with advanced compilation, the bundle size, especially when combined with other dependencies, is smaller than what you get with self-hosted CLJS. That makes startup faster. The trade-off is that execution is less performant and that only a subset of CLJS is available (e.g. no deftype, yet).

Usage

Install nbb from NPM:

$ npm install nbb -g

Omit -g for a local install.

Try out an expression:

$ nbb -e '(+ 1 2 3)'
6

And then install some other NPM libraries to use in the script. E.g.:

$ npm install csv-parse shelljs zx

Create a script which uses the NPM libraries:

(ns script
  (:require ["csv-parse/lib/sync$default" :as csv-parse]
            ["fs" :as fs]
            ["path" :as path]
            ["shelljs$default" :as sh]
            ["term-size$default" :as term-size]
            ["zx$default" :as zx]
            ["zx$fs" :as zxfs]
            [nbb.core :refer [*file*]]))

(prn (path/resolve "."))

(prn (term-size))

(println (count (str (fs/readFileSync *file*))))

(prn (sh/ls "."))

(prn (csv-parse "foo,bar"))

(prn (zxfs/existsSync *file*))

(zx/$ #js ["ls"])

Call the script:

$ nbb script.cljs
"/private/tmp/test-script"
#js {:columns 216, :rows 47}
510
#js ["node_modules" "package-lock.json" "package.json" "script.cljs"]
#js [#js ["foo" "bar"]]
true
$ ls
node_modules
package-lock.json
package.json
script.cljs

Macros

Nbb has first class support for macros: you can define them right inside your .cljs file, like you are used to from JVM Clojure. Consider the plet macro to make working with promises more palatable:

(defmacro plet
  [bindings & body]
  (let [binding-pairs (reverse (partition 2 bindings))
        body (cons 'do body)]
    (reduce (fn [body [sym expr]]
              (let [expr (list '.resolve 'js/Promise expr)]
                (list '.then expr (list 'clojure.core/fn (vector sym)
                                        body))))
            body
            binding-pairs)))

Using this macro we can look async code more like sync code. Consider this puppeteer example:

(-> (.launch puppeteer)
      (.then (fn [browser]
               (-> (.newPage browser)
                   (.then (fn [page]
                            (-> (.goto page "https://clojure.org")
                                (.then #(.screenshot page #js{:path "screenshot.png"}))
                                (.catch #(js/console.log %))
                                (.then #(.close browser)))))))))

Using plet this becomes:

(plet [browser (.launch puppeteer)
       page (.newPage browser)
       _ (.goto page "https://clojure.org")
       _ (-> (.screenshot page #js{:path "screenshot.png"})
             (.catch #(js/console.log %)))]
      (.close browser))

See the puppeteer example for the full code.

Since v0.0.36, nbb includes promesa which is a library to deal with promises. The above plet macro is similar to promesa.core/let.

Startup time

$ time nbb -e '(+ 1 2 3)'
6
nbb -e '(+ 1 2 3)'   0.17s  user 0.02s system 109% cpu 0.168 total

The baseline startup time for a script is about 170ms seconds on my laptop. When invoked via npx this adds another 300ms or so, so for faster startup, either use a globally installed nbb or use $(npm bin)/nbb script.cljs to bypass npx.

Dependencies

NPM dependencies

Nbb does not depend on any NPM dependencies. All NPM libraries loaded by a script are resolved relative to that script. When using the Reagent module, React is resolved in the same way as any other NPM library.

Classpath

To load .cljs files from local paths or dependencies, you can use the --classpath argument. The current dir is added to the classpath automatically. So if there is a file foo/bar.cljs relative to your current dir, then you can load it via (:require [foo.bar :as fb]). Note that nbb uses the same naming conventions for namespaces and directories as other Clojure tools: foo-bar in the namespace name becomes foo_bar in the directory name.

To load dependencies from the Clojure ecosystem, you can use the Clojure CLI or babashka to download them and produce a classpath:

$ classpath="$(clojure -A:nbb -Spath -Sdeps '{:aliases {:nbb {:replace-deps {com.github.seancorfield/honeysql {:git/tag "v2.0.0-rc5" :git/sha "01c3a55"}}}}}')"

and then feed it to the --classpath argument:

$ nbb --classpath "$classpath" -e "(require '[honey.sql :as sql]) (sql/format {:select :foo :from :bar :where [:= :baz 2]})"
["SELECT foo FROM bar WHERE baz = ?" 2]

Currently nbb only reads from directories, not jar files, so you are encouraged to use git libs. Support for .jar files will be added later.

Current file

The name of the file that is currently being executed is available via nbb.core/*file* or on the metadata of vars:

(ns foo
  (:require [nbb.core :refer [*file*]]))

(prn *file*) ;; "/private/tmp/foo.cljs"

(defn f [])
(prn (:file (meta #'f))) ;; "/private/tmp/foo.cljs"

Reagent

Nbb includes reagent.core which will be lazily loaded when required. You can use this together with ink to create a TUI application:

$ npm install ink

ink-demo.cljs:

(ns ink-demo
  (:require ["ink" :refer [render Text]]
            [reagent.core :as r]))

(defonce state (r/atom 0))

(doseq [n (range 1 11)]
  (js/setTimeout #(swap! state inc) (* n 500)))

(defn hello []
  [:> Text {:color "green"} "Hello, world! " @state])

(render (r/as-element [hello]))

Promesa

Working with callbacks and promises can become tedious. Since nbb v0.0.36 the promesa.core namespace is included with the let and do! macros. An example:

(ns prom
  (:require [promesa.core :as p]))

(defn sleep [ms]
  (js/Promise.
   (fn [resolve _]
     (js/setTimeout resolve ms))))

(defn do-stuff
  []
  (p/do!
   (println "Doing stuff which takes a while")
   (sleep 1000)
   1))

(p/let [a (do-stuff)
        b (inc a)
        c (do-stuff)
        d (+ b c)]
  (prn d))
$ nbb prom.cljs
Doing stuff which takes a while
Doing stuff which takes a while
3

Also see API docs.

Js-interop

Since nbb v0.0.75 applied-science/js-interop is available:

(ns example
  (:require [applied-science.js-interop :as j]))

(def o (j/lit {:a 1 :b 2 :c {:d 1}}))

(prn (j/select-keys o [:a :b])) ;; #js {:a 1, :b 2}
(prn (j/get-in o [:c :d])) ;; 1

Most of this library is supported in nbb, except the following:

  • destructuring using :syms
  • property access using .-x notation. In nbb, you must use keywords.

See the example of what is currently supported.

Examples

See the examples directory for small examples.

Also check out these projects built with nbb:

API

See API documentation.

Migrating to shadow-cljs

See this gist on how to convert an nbb script or project to shadow-cljs.

Build

Prequisites:

  • babashka >= 0.4.0
  • Clojure CLI >= 1.10.3.933
  • Node.js 16.5.0 (lower version may work, but this is the one I used to build)

To build:

  • Clone and cd into this repo
  • bb release

Run bb tasks for more project-related tasks.

Download Details:
Author: borkdude
Download Link: Download The Source Code
Official Website: https://github.com/borkdude/nbb 
License: EPL-1.0

#node #javascript

I am Developer

1608637001

Laravel 8 Get Country, City Address From IP Address

How to get country name from IP address in Laravel 8 app. In this tutorial, i will show you How to get country city state zip code metro code from IP address in Laravel 8 app.

How to get location(county,city address) information from ip address in Laravel

  • Step 1 - Install Laravel 8 App
  • Step 2 - Connecting App to Database
  • Step 3 - Install "stevebauman/location"
  • Step 4 - Add Routes
  • Step 5 - Create Controller By Command
  • Step 6 - Start Development Server

https://www.tutsmake.com/laravel-8-get-country-city-address-from-ip-address-tutorial/

#get location from ip address in laravel #laravel address from ip address #laravel get country city from ip address #laravel get user country by ip #laravel geoip to address

Sheldon  Grant

Sheldon Grant

1652085928

Ipaddr.js: IP Address Manipulation Library in JavaScript

ipaddr.js — An IPv6 and IPv4 address manipulation library

ipaddr.js is a small (1.9K minified and gzipped) library for manipulating IP addresses in JavaScript environments. It runs on both CommonJS runtimes (e.g. nodejs) and in a web browser.

ipaddr.js allows you to verify and parse string representation of an IP address, match it against a CIDR range or range list, determine if it falls into some reserved ranges (examples include loopback and private ranges), and convert between IPv4 and IPv4-mapped IPv6 addresses.

Installation

npm install ipaddr.js

or

bower install ipaddr.js

Older Node support

Use 2.x release for nodejs versions 10+. Use the 1.x release for versions of nodejs older than 10.

API

ipaddr.js defines one object in the global scope: ipaddr. In CommonJS, it is exported from the module:

const ipaddr = require('ipaddr.js');

The API consists of several global methods and two classes: ipaddr.IPv6 and ipaddr.IPv4.

Global methods

There are three global methods defined: ipaddr.isValid, ipaddr.parse and ipaddr.process. All of them receive a string as a single parameter.

The ipaddr.isValid method returns true if the address is a valid IPv4 or IPv6 address, and false otherwise. It does not throw any exceptions.

The ipaddr.parse method returns an object representing the IP address, or throws an Error if the passed string is not a valid representation of an IP address.

The ipaddr.process method works just like the ipaddr.parse one, but it automatically converts IPv4-mapped IPv6 addresses to their IPv4 counterparts before returning. It is useful when you have a Node.js instance listening on an IPv6 socket, and the net.ivp6.bindv6only sysctl parameter (or its equivalent on non-Linux OS) is set to 0. In this case, you can accept IPv4 connections on your IPv6-only socket, but the remote address will be mangled. Use ipaddr.process method to automatically demangle it.

Object representation

Parsing methods return an object which descends from ipaddr.IPv6 or ipaddr.IPv4. These objects share some properties, but most of them differ.

Shared properties

One can determine the type of address by calling addr.kind(). It will return either "ipv6" or "ipv4".

An address can be converted back to its string representation with addr.toString(). Note that this method:

  • does not return the original string used to create the object (in fact, there is no way of getting that string)
  • returns a compact representation (when it is applicable)

A match(range, bits) method can be used to check if the address falls into a certain CIDR range. Note that an address can be (obviously) matched only against an address of the same type.

For example:

const addr  = ipaddr.parse('2001:db8:1234::1');
const range = ipaddr.parse('2001:db8::');

addr.match(range, 32); // => true

Alternatively, match can also be called as match([range, bits]). In this way, it can be used together with the parseCIDR(string) method, which parses an IP address together with a CIDR range.

For example:

const addr = ipaddr.parse('2001:db8:1234::1');

addr.match(ipaddr.parseCIDR('2001:db8::/32')); // => true

A range() method returns one of predefined names for several special ranges defined by IP protocols. The exact names (and their respective CIDR ranges) can be looked up in the source: IPv6 ranges and IPv4 ranges. Some common ones include "unicast" (the default one) and "reserved".

You can match against your own range list by using ipaddr.subnetMatch(address, rangeList, defaultName) method. It can work with a mix of IPv6 or IPv4 addresses, and accepts a name-to-subnet map as the range list. For example:

const rangeList = {
  documentationOnly: [ ipaddr.parse('2001:db8::'), 32 ],
  tunnelProviders: [
    [ ipaddr.parse('2001:470::'), 32 ], // he.net
    [ ipaddr.parse('2001:5c0::'), 32 ]  // freenet6
  ]
};
ipaddr.subnetMatch(ipaddr.parse('2001:470:8:66::1'), rangeList, 'unknown'); // => "tunnelProviders"

The addresses can be converted to their byte representation with toByteArray(). (Actually, JavaScript mostly does not know about byte buffers. They are emulated with arrays of numbers, each in range of 0..255.)

const bytes = ipaddr.parse('2a00:1450:8007::68').toByteArray(); // ipv6.google.com
bytes // => [42, 0x00, 0x14, 0x50, 0x80, 0x07, 0x00, <zeroes...>, 0x00, 0x68 ]

The ipaddr.IPv4 and ipaddr.IPv6 objects have some methods defined, too. All of them have the same interface for both protocols, and are similar to global methods.

ipaddr.IPvX.isValid(string) can be used to check if the string is a valid address for particular protocol, and ipaddr.IPvX.parse(string) is the error-throwing parser.

ipaddr.IPvX.isValid(string) uses the same format for parsing as the POSIX inet_ntoa function, which accepts unusual formats like 0xc0.168.1.1 or 0x10000000. The function ipaddr.IPv4.isValidFourPartDecimal(string) validates the IPv4 address and also ensures that it is written in four-part decimal format.

IPv6 properties

Sometimes you will want to convert IPv6 not to a compact string representation (with the :: substitution); the toNormalizedString() method will return an address where all zeroes are explicit.

For example:

const addr = ipaddr.parse('2001:0db8::0001');
addr.toString(); // => '2001:db8::1'
addr.toNormalizedString(); // => '2001:db8:0:0:0:0:0:1'

The isIPv4MappedAddress() method will return true if this address is an IPv4-mapped one, and toIPv4Address() will return an IPv4 object address.

To access the underlying binary representation of the address, use addr.parts.

const addr = ipaddr.parse('2001:db8:10::1234:DEAD');
addr.parts // => [0x2001, 0xdb8, 0x10, 0, 0, 0, 0x1234, 0xdead]

A IPv6 zone index can be accessed via addr.zoneId:

const addr = ipaddr.parse('2001:db8::%eth0');
addr.zoneId // => 'eth0'

IPv4 properties

toIPv4MappedAddress() will return a corresponding IPv4-mapped IPv6 address.

To access the underlying representation of the address, use addr.octets.

const addr = ipaddr.parse('192.168.1.1');
addr.octets // => [192, 168, 1, 1]

prefixLengthFromSubnetMask() will return a CIDR prefix length for a valid IPv4 netmask or null if the netmask is not valid.

ipaddr.IPv4.parse('255.255.255.240').prefixLengthFromSubnetMask() == 28
ipaddr.IPv4.parse('255.192.164.0').prefixLengthFromSubnetMask()  == null

subnetMaskFromPrefixLength() will return an IPv4 netmask for a valid CIDR prefix length.

ipaddr.IPv4.subnetMaskFromPrefixLength(24) == '255.255.255.0'
ipaddr.IPv4.subnetMaskFromPrefixLength(29) == '255.255.255.248'

broadcastAddressFromCIDR() will return the broadcast address for a given IPv4 interface and netmask in CIDR notation.

ipaddr.IPv4.broadcastAddressFromCIDR('172.0.0.1/24') == '172.0.0.255'

networkAddressFromCIDR() will return the network address for a given IPv4 interface and netmask in CIDR notation.

ipaddr.IPv4.networkAddressFromCIDR('172.0.0.1/24') == '172.0.0.0'

Conversion

IPv4 and IPv6 can be converted bidirectionally to and from network byte order (MSB) byte arrays.

The fromByteArray() method will take an array and create an appropriate IPv4 or IPv6 object if the input satisfies the requirements. For IPv4 it has to be an array of four 8-bit values, while for IPv6 it has to be an array of sixteen 8-bit values.

For example:

const addr = ipaddr.fromByteArray([0x7f, 0, 0, 1]);
addr.toString(); // => '127.0.0.1'

or

const addr = ipaddr.fromByteArray([0x20, 1, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
addr.toString(); // => '2001:db8::1'

Both objects also offer a toByteArray() method, which returns an array in network byte order (MSB).

For example:

const addr = ipaddr.parse('127.0.0.1');
addr.toByteArray(); // => [0x7f, 0, 0, 1]

or

const addr = ipaddr.parse('2001:db8::1');
addr.toByteArray(); // => [0x20, 1, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]

Author: Whitequark
Source Code: https://github.com/whitequark/ipaddr.js 
License: MIT license

#node #javascript #ip 

Ajay Kapoor

1626321063

JS Development Company India | JavaScript Development Services

PixelCrayons: Our JavaScript web development service offers you a feature-packed & dynamic web application that effectively caters to your business challenges and provide you the best RoI. Our JavaScript web development company works on all major frameworks & libraries like Angular, React, Nodejs, Vue.js, to name a few.

With 15+ years of domain expertise, we have successfully delivered 13800+ projects and have successfully garnered 6800+ happy customers with 97%+ client retention rate.

Looking for professional JavaScript web app development services? We provide custom JavaScript development services applying latest version frameworks and libraries to propel businesses to the next level. Our well-defined and manageable JS development processes are balanced between cost, time and quality along with clear communication.

Our JavaScript development companies offers you strict NDA, 100% money back guarantee and agile/DevOps approach.

#javascript development company #javascript development services #javascript web development #javascript development #javascript web development services #javascript web development company

Sheldon  Grant

Sheldon Grant

1652134380

Cidr: Javascript Library for Manipulating IP Addresses

node-cidr

node-cidr is a Javascript library that makes it easy to manipulate IPs and Subnets. Currently only IPv4 is supported, but IPv6 support is planned for a future release.


Variables

«Const» invalidChars

● invalidChars: RegExp = /^.?(?=[^#%&$*:<>?/{|}[a-zA-Z]).$/

Defined in index.ts:3


Functions

«Const» address

address(ip: string): string

Defined in index.ts:155

Parameters:

ParamTypeDescription
ipstring-

Returns: string


«Const» broadcast

broadcast(cidr: string): string

Defined in index.ts:175

Parameters:

ParamTypeDescription
cidrstring-

Returns: string


«Const» cidrCommonCidr

cidrCommonCidr(cidrs: string[]): string

Defined in index.ts:166

Parameters:

ParamTypeDescription
cidrsstring[]-

Returns: string


«Const» count

count(cidr: string): number

Defined in index.ts:190

Parameters:

ParamTypeDescription
cidrstring-

Returns: number


«Const» includes

includes(cidr: string, ip: string): boolean

Defined in index.ts:240

Parameters:

ParamTypeDescription
cidrstring-
ipstring-

Returns: boolean


«Const» intCommonCidr

intCommonCidr(ips: number[]): string

Defined in index.ts:5

Parameters:

ParamTypeDescription
ipsnumber[]-

Returns: string


«Const» ipCommonCidr

ipCommonCidr(ips: string[]): string

Defined in index.ts:57

Parameters:

ParamTypeDescription
ipsstring[]-

Returns: string


«Const» ips

ips(cidr: string): string[]

Defined in index.ts:229

Parameters:

ParamTypeDescription
cidrstring-

Returns: string[]


«Const» mask

mask(ip: string): number

Defined in index.ts:157

Parameters:

ParamTypeDescription
ipstring-

Returns: number


«Const» max

max(cidr: string): string

Defined in index.ts:184

Parameters:

ParamTypeDescription
cidrstring-

Returns: string


«Const» min

min(cidr: string): string

Defined in index.ts:177

Parameters:

ParamTypeDescription
cidrstring-

Returns: string


«Const» netmask

netmask(cidr: string): string

Defined in index.ts:172

Parameters:

ParamTypeDescription
cidrstring-

Returns: string


«Const» next

next(ip: string): string

Defined in index.ts:111

Returns the next adjacent address.

Parameters:

ParamTypeDescription
ipstring-

Returns: string


«Const» nextCidr

nextCidr(cidr: string): string

Defined in index.ts:245

Parameters:

ParamTypeDescription
cidrstring-

Returns: string


«Const» padLeft

padLeft(input: string, char: string, min: number): string

Defined in index.ts:26

Parameters:

ParamTypeDescription
inputstring-
charstring-
minnumber-

Returns: string


«Const» previous

previous(ip: string): string

Defined in index.ts:117

Returns the previous adjacent address.

Parameters:

ParamTypeDescription
ipstring-

Returns: string


«Const» previousCidr

previousCidr(cidr: string): string

Defined in index.ts:248

Parameters:

ParamTypeDescription
cidrstring-

Returns: string


«Const» random

random(cidr: string): string

Defined in index.ts:251

Parameters:

ParamTypeDescription
cidrstring-

Returns: string


«Const» reverse

reverse(ip: stringnumber): string

Defined in index.ts:73

Returns the reverse lookup hostname for the address.

Parameters:

ParamTypeDescription
ipstringnumber-

Returns: string


«Const» subnets

subnets(cidr: string, subMask: number, limit: number): string[]

Defined in index.ts:206

Parameters:

ParamTypeDescription
cidrstring-
subMasknumber-
limitnumber-

Returns: string[]


«Const» toBinary

toBinary(ip: stringnumber): string

Defined in index.ts:84

Returns the binary representation of the address, in string form.

Parameters:

ParamTypeDescription
ipstringnumber-

Returns: string


«Const» toCidr

toCidr(ip: stringnumber): string

Defined in index.ts:119

Parameters:

ParamTypeDescription
ipstringnumber-

Returns: string


«Const» toHex

toHex(ip: stringnumber): string

Defined in index.ts:97

Provides the hex value of the address.

Parameters:

ParamTypeDescription
ipstringnumber-

Returns: string


«Const» toInt

toInt(ipAddress: string): number

Defined in index.ts:35

Parameters:

ParamTypeDescription
ipAddressstring-

Returns: number


«Const» toIntRange

toIntRange(cidr: string): number[]

Defined in index.ts:159

Parameters:

ParamTypeDescription
cidrstring-

Returns: number[]


«Const» toOctets

toOctets(input: stringnumber): number[]

Defined in index.ts:62

Parameters:

ParamTypeDescription
inputstringnumber-

Returns: number[]


«Const» toRange

toRange(cidr: string): string[]

Defined in index.ts:164

Parameters:

ParamTypeDescription
cidrstring-

Returns: string[]


«Const» toString

toString(ipInt: number): string

Defined in index.ts:43

Parameters:

ParamTypeDescription
ipIntnumber-

Returns: string


«Const» usable

usable(cidr: string): string[]

Defined in index.ts:192

Parameters:

ParamTypeDescription
cidrstring-

Returns: string[]


«Const» validateCidr

validateCidr(cidr: string): stringnull

Defined in index.ts:256

Parameters:

ParamTypeDescription
cidrstring-

Returns: stringnull


«Const» validateIp

validateIp(ip: string): stringnull

Defined in index.ts:126

Parameters:

ParamTypeDescription
ipstring-

Returns: stringnull


«Const» wildcardmask

wildcardmask(cidr: string): string

Defined in index.ts:203

Parameters:

ParamTypeDescription
cidrstring-

Returns: string


Object literal: cidr

address

● address: address

Defined in index.ts:287


broadcast

● broadcast: broadcast

Defined in index.ts:280


commonCidr

● commonCidr: cidrCommonCidr = cidrCommonCidr

Defined in index.ts:274


count

● count: count

Defined in index.ts:277


includes

● includes: includes

Defined in index.ts:283


ips

● ips: ips

Defined in index.ts:282


mask

● mask: mask

Defined in index.ts:288


max

● max: max

Defined in index.ts:275


min

● min: min

Defined in index.ts:276


netmask

● netmask: netmask

Defined in index.ts:278


next

● next: nextCidr = nextCidr

Defined in index.ts:285


previous

● previous: previousCidr = previousCidr

Defined in index.ts:286


random

● random: random

Defined in index.ts:284


subnets

● subnets: subnets

Defined in index.ts:281


toIntRange

● toIntRange: toIntRange

Defined in index.ts:273


toRange

● toRange: toRange

Defined in index.ts:271


usable

● usable: usable

Defined in index.ts:272


validate

● validate: validateCidr = validateCidr

Defined in index.ts:289


wildcardmask

● wildcardmask: wildcardmask

Defined in index.ts:279


Object literal: ip

commonCidr

● commonCidr: ipCommonCidr = ipCommonCidr

Defined in index.ts:142


next

● next: next

Defined in index.ts:148


previous

● previous: previous

Defined in index.ts:147


reverse

● reverse: reverse

Defined in index.ts:146


toBinary

● toBinary: toBinary

Defined in index.ts:145


toCidr

● toCidr: toCidr

Defined in index.ts:149


toHex

● toHex: toHex

Defined in index.ts:143


toInt

● toInt: toInt

Defined in index.ts:140


toOctets

● toOctets: toOctets

Defined in index.ts:144


toString

● toString: toString

Defined in index.ts:141


validate

● validate: validateIp = validateIp

Defined in index.ts:150


Author: Arminhammer
Source Code: https://github.com/arminhammer/node-cidr 
License: Apache-2.0 license

#node #javascript #ip