Clojure library for modeling various Internet-related conceptual entities as data
Clojure Other Java Shell
Pull request Compare This branch is 40 commits behind damballa:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dev-resources
resources
src
test/inet/data
.gitignore
README.md
gendoc.sh
project.clj

README.md

inet.data

Inet.data is a library for modeling various Internet-related conceptual entities as data, supporting applications which are about the modeled entities versus interfacing with them.

Installation

Inet.data is available on Clojars. Add this :dependency to your Leiningen project.clj:

[inet.data "0.5.1"]

Usage

Currently inet.data includes support for IP addresses and networks and for DNS domain names. Example usage follows; detailed API documentation available.

inet.data.ip

The inet.data.ip namespace defines types for IP addresses and networks and associated functions. All public functions work in terms of a protocol which is also implemented for strings, byte arrays, and java.net.InetAddress.

(require '[inet.data.ip :as ip])

(ip/network-contains? "192.168.1.0/24" "192.168.1.1") ;;=> true

(ip/address? "600d::") ;;=> true
(ip/address? "::bad::") ;;=> false

(let [rfc1918 (ip/network-set "10.0.0.0/8" "172.16.0.0/12" "192.168.0.0/16")]
  (get rfc1918 "10.31.33.7") ;;=> (#ip/network "10.0.0.0/8")
  (get rfc1918 "8.8.8.8") ;;=> nil
  )

(seq (ip/network "192.168.0.0/30"))
;;=> (#ip/address "192.168.0.0"
;;    #ip/address "192.168.0.1"
;;    #ip/address "192.168.0.2"
;;    #ip/address "192.168.0.3")

(ip/network-nth "192.168.0.0/30" -1)
;;=> #ip/address "192.168.0.3"

(ip/address-networks "192.168.0.0" "192.168.0.4")
;;=> #{#ip/network "192.168.0.0/30"
;;     #ip/network "192.168.0.4/32"}

inet.data.dns

The inet.data.dns namespace defines a type for representing DNS domain names and associated functions. All public functions work in terms of a protocol which is also implemented for strings and byte arrays.

(require '[inet.data.dns :as dns])

(dns/domain-contains? "com" "example.com") ;;=> true

(dns/domain? "example.com") ;;=> true
(dns/domain? "bad..com") ;;=> false

(dns/domain-parent "www.example.com") ;;=> #dns/domain "example.com"

(let [gtlds (dns/domain-set "com" "net" "org")]
  (get gtlds "example.com") ;;=> (#dns/domain "com")
  (get gtld "does.not.exist") ;;=> nil
  )

inet.data.format.psl

The inet.data.format.psl namespace defines functions for working with files in the Mozilla Public Suffix List format. It can automatically use the current version of the list as maintained by the Mozilla project. The format is generally useful for domain suffix applications, but most applications will need to provide their own list(s) customized for their particular use cases.

(require '[inet.data.format.psl :as psl])

(psl/lookup "www.example.co.uk") ;;=> #dns/domain "example.co.uk"

License

Copyright (C) 2012 Marshall T. Vandegrift

Distributed under the Eclipse Public License, the same as Clojure.