Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » 32-bit integers IP address to 4-octet IP address [RSS Feed]

#1 Jan. 23, 2011 13:25:23

Phillip B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

32-bit integers IP address to 4-octet IP address


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Dear All,

I've started playing around with Django in the last few days, and I'm
enjoying the speed
and the power of such framework. I'm writing a small application to
display and sort
ip addresses stored in a Postgresql database, right now I'm stuck with
32-bit integers
IP address translated to 4-octet IP address .

Here's the the class of the ip address.

class Iphdr(models.Model):
sid = models.IntegerField(primary_key=True)
cid = models.BigIntegerField(primary_key=True)
ip_src = models.BigIntegerField()
ip_dst = models.BigIntegerField()
ip_ver = models.SmallIntegerField()
ip_hlen = models.SmallIntegerField()
ip_tos = models.SmallIntegerField()
ip_len = models.IntegerField()
ip_id = models.IntegerField()
ip_flags = models.SmallIntegerField()
ip_off = models.IntegerField()
ip_ttl = models.SmallIntegerField()
ip_proto = models.SmallIntegerField()
ip_csum = models.IntegerField()
class Meta:
db_table = u'iphdr'


As the IP addresses are stored in the database as unsigned 32-bit
integers, so when I
run ip = Iphdr.objects.values("ip_src") the result is in 32-bit integers,

{'ip_src': 3251031814L}{'ip_src': 3251031816L}{'ip_src': 3251031816L}
{'ip_src': 3251031816L}{'ip_src': 3251031814L}{'ip_src': 3251031816L}

There's any elegant solution that can translate 32-bit integers to
4-octet IP address (192.168.1.88) ?

Thanks in advance.

Phillip
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQEcBAEBAgAGBQJNO++eAAoJENNBJKHbaDgTM0cH/0/QjdPTi53tJG4YhjVpt6oj
cJk6rAEHwFha//Vby4lH2sT+ZyKmv+UAjSVmvBCptXBOcm5LuedMmMCVeInfuliQ
GeOPlQ4nvrZSbcdXirLu9Jqa+Yqj6nalGF7i0WetqvdsdrkQQdrcx1D814DSZKGq
qQWpdyVEmdrRSfiOUvrYbnXDCnTwCXZdUhcpDNmD+5h9S2/uiMzP5cM2wtfMg1hO
swYS9B7h/6vAd1ekOZh+ij2X4mszUfp5rQzFjCXtYnQma8pN+58UMpWwYVKj2FzA
tgRaWC1Qz4hWsXRvwirqo/ZtyJMWxkOdwVaxl3iug/NCGW/yDCMa97zweYOHKCs=
=W+IC
-----END PGP SIGNATURE-----

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.0xDB683813.ascDescription:application/pgp-keys

Attachments:
attachment 0xDB683813.asc (1.7 KB)

Offline

  • Root
  • » Django
  • » 32-bit integers IP address to 4-octet IP address [RSS Feed]

Board footer

Moderator control

Enjoy the 21st of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support