Skip to content

Instantly share code, notes, and snippets.

@hbasria
Created July 7, 2015 15:26
Show Gist options
  • Save hbasria/f9209ae98e80c0975bee to your computer and use it in GitHub Desktop.
Save hbasria/f9209ae98e80c0975bee to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION is_private_ip(p_prefix inet) RETURNS boolean AS
$BODY$
BEGIN
RETURN (
SELECT
CASE
WHEN '10.0.0.0/8'::inet >> p_prefix::inet
OR '192.168.0.0/16'::inet >> p_prefix::inet
OR '172.16.0.0/12'::inet >> p_prefix::inet THEN True
ELSE False
END);
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment