/ipcheck

ipcheck $my_ip -> { malformed | public | private | loopback | linklocal }

Primary LanguageGoGNU General Public License v3.0GPL-3.0

ipcheck

CircleCI Go Report Card codecov

A statically linked binary which, given a string decides if it is

  • malformed: not an IPv4 address
  • public: a routable IPv4 address
  • private: a non-routable IPv4 per rfc1918
  • loopback: rfc1700
  • linklocal: rfc3927
  • 6to4: rfc3068
  • documentation: rfc5737

See wikipedia for all the gory details.

Usage

In your dockerfile, add something like this:

FROM alpine

ENV IPCHECK_VERSION="0.1"

RUN apk --no-cache add curl  \
 && curl -o /usr/local/sbin/ipcheck https://github.com/ahammond/ipcheck/releases/download/v$IPCHECK_VERSION/ipcheck

CMD [ "entrypoint.sh" ]

And then in your entrypoint.sh or wherever you're doing validation:

IP_TYPE=$(ipcheck "$MY_IP")
if [ "public" != "$IP_TYPE" ]; then
  echo "I need a public IP, but $MY_IP is $IP_TYPE"
  exit 1
fi