Login

Tag "ip-address"

Snippet List

Test IP against IP address+Subnet whitelist

Simple function that tests whether a given IP address is in a list of IP addresses or subnets. Requires `ipaddr`. Comes with Python 2.7 or 3.1, [downloadable here](http://code.google.com/p/ipaddr-py/) for earlier versions. More info on `ipaddr` [in Python 3.1 docs](http://docs.python.org/dev/py3k/library/ipaddr.html).

  • ip-address
  • whitelist
  • ipaddr
  • subnet
Read More

Tuned IPAddressField with IPv4 & IPv6 support using Postgres Network Field type

I wanted to store ipv4 and ipv6 ip's in django but I wanted to use the postgresql inet network field type: http://www.postgresql.org/docs/8.3/static/datatype-net-types.html and I wanted to use IPy.py IP objects in python. I followed these very helpful examples along with the django documentation: http://vaig.be/2009/03/numeric-ip-field-for-django.html http://www.djangosnippets.org/snippets/1381/ It took me awhile to figure out how this works (not that I completely understand it now..) and figured I would share it. If anyone finds problems with this or can make it better I will definitely use it.

  • model
  • field
  • ip
  • custom
  • ip-address
  • ip-addresses
  • ipv4
  • ipv6
  • ipy
  • postgresql-network-field
Read More

Block IP addresses

I needed a quick and dirty way to block a user from my site. Just include this middleware class under the 'MIDDLEWARE_CLASSES' variable in your settings.py file. Also include the variable BLOCKED_IPS = ('123.123.123.123',) variable, where the value is a tuple of IP addresses you want blocked from your site.

  • middleware
  • ip-address
Read More

4 snippets posted so far.