converting an IP string to long integer:
import socket, struct
def ip2long(ip):
"""
Convert an IP string to long
"""
packedIP = socket.inet_aton(ip)
return struct.unpack("!L", packedIP)[0]
the other way around:
>>> socket.inet_ntoa(struct.pack('!L', 2130706433))
'127.0.0.1'
More Related Contents:
- Django -> queryset[index] Index out of range
- django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. plz help me out plz
- How to pull a random record using Django’s ORM?
- Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren’t loaded yet
- How do I perform HTML decoding/encoding using Python/Django?
- How to send email via Django?
- Get Timezone from City in Python/Django
- How to replace Django’s primary key with a different integer that is unique for that table
- multiple django sites with apache & mod_wsgi
- How can I get the domain name of my site within a Django template?
- Django 1.7 – “No migrations to apply” when run migrate after makemigrations
- django – convert a list back to a queryset [duplicate]
- How to set up custom middleware in Django
- How to write setup.py to include a Git repository as a dependency
- How do I separate my models out in django?
- django best approach for creating multiple type users
- When should I use escape and safe in Django’s template system?
- Using request.user with Django ModelForm
- How to execute arithmetic operations between Model fields in django
- gunicorn autoreload on source change
- What is the best approach to change primary keys in an existing Django app?
- Order of Serializer Validation in Django REST Framework
- Difference between AbstractUser and AbstractBaseUser in Django?
- How to expire Django session in 5minutes?
- How to perform OR condition in django queryset?
- Django Admin – Disable the ‘Add’ action for a specific model
- Django equivalent of PHP’s form value array/associative array
- Add “django-admin.py” path to command line on Windows 7
- Django Multiple Databases – relation does not exist; LINE 1: SELECT COUNT(*) AS “__count” FROM
- How do I change the range of the x-axis with datetime?