Skip to content
/ rip Public

Rip out the real IP address of a client from all the available data we have in a request

License

Notifications You must be signed in to change notification settings

ripexz/rip

Repository files navigation

rip

GoDoc

Go package that can be used to get client's real public IP. Based on https://github.com/tomasen/realip.

Features

  • Parses IPs from X-Real-IP
  • Parses IPs from X-Forwarded-For
  • Excludes local/private address by default
  • Custom filtering options for X-Forwarded-For IPs

Examples

Basic usage

package main

import "github.com/ripexz/rip"

func (h *Handler) ServeIndexPage(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
	clientIP := rip.FromRequest(r, nil)
	log.Println("GET / from", clientIP)
}

AWS ELB

clientIP := rip.FromRequest(r, rip.FilterAWS)

Custom Filtering

clientIP := rip.FromRequest(r, func(ips []string) (string, bool) {
	// your custom logic here
	return "127.0.0.1", true
})

Contributing

Please make sure your code:

  • Passes the configured golangci-lint checks.
  • Passes the tests.

About

Rip out the real IP address of a client from all the available data we have in a request

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages