1 """
2 Misc. utility functions. It is part of the pygeoip package.
3
4 @author: Jennifer Ennis <zaylea at gmail dot com>
5
6 @license:
7 Copyright(C) 2004 MaxMind LLC
8
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/lgpl.txt>.
21 """
22
23 import six
24
26 """
27 Convert a IPv4 address into a 32-bit integer.
28
29 @param ip: quad-dotted IPv4 address
30 @type ip: str
31 @return: network byte order 32-bit integer
32 @rtype: int
33 """
34 ip_array = ip.split('.')
35
36 if six.PY3:
37
38 ip_long = int(ip_array[0]) * 16777216 + int(ip_array[1]) * 65536 + int(ip_array[2]) * 256 + int(ip_array[3])
39 else:
40 ip_long = long(ip_array[0]) * 16777216 + long(ip_array[1]) * 65536 + long(ip_array[2]) * 256 + long(ip_array[3])
41 return ip_long
42