Skip to content
/ ip Public

IP CIDR range based filtering and multiplexer for your proxies

License

Notifications You must be signed in to change notification settings

vinxi/ip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ip Build Status GoDoc Coverage Status Go Report Card

IP range based filtering and multiplexer for your proxies. Supports IP v4/v6 expressions, CIDR ranges, subnets...

Implements a middleware layer, so you can use it as multiplexer.

Installation

go get -u gopkg.in/vinxi/ip.v0

API

See godoc reference.

Example

Allow reserved loopback CIDR ranges

package main

import (
  "fmt"

  "gopkg.in/vinxi/ip.v0"
  "gopkg.in/vinxi/vinxi.v0"
)

const port = 3100

func main() {
  // Create a new vinxi proxy
  vs := vinxi.NewServer(vinxi.ServerOptions{Port: port})

  // Attach the IP range filter
  vs.Use(ip.New("127.0.0.1/8", "::1/64"))

  // Target server to forward
  vs.Forward("http://httpbin.org")

  fmt.Printf("Server listening on port: %d\n", port)
  err := vs.Listen()
  if err != nil {
    fmt.Errorf("Error: %s\n", err)
  }
}

Use filter as multiplexer for middleware composition

package main

import (
  "fmt"
  "net/http"

  "gopkg.in/vinxi/ip.v0"
  "gopkg.in/vinxi/vinxi.v0"
)

const port = 3100

func main() {
  // Create a new vinxi proxy
  vs := vinxi.NewServer(vinxi.ServerOptions{Port: port})

  // Create the IP filter
  filter := ip.New("127.0.0.1/8", "::1/64")

  // Attach a filter level middleware handler
  filter.Use(func(w http.ResponseWriter, r *http.Request, h http.Handler) {
    w.Header().Set("IP-Allowed", r.RemoteAddr)
    h.ServeHTTP(w, r)
  })

  // Register the filter in vinxi
  vs.Use(filter)

  // Target server to forward
  vs.Forward("http://httpbin.org")

  fmt.Printf("Server listening on port: %d\n", port)
  err := vs.Listen()
  if err != nil {
    fmt.Errorf("Error: %s\n", err)
  }
}

License

MIT

About

IP CIDR range based filtering and multiplexer for your proxies

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages