1
2 """
3 Utility function for address translation
4
5 @author: Jennifer Ennis <zaylea@gmail.com>
6 @author: William Tisäter <william@defunct.cc>
7
8 @license: Copyright(C) 2004 MaxMind LLC
9
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/lgpl.txt>.
22 """
23
24 import socket
25 import binascii
26
27
29 """
30 Wrapper function for IPv4 and IPv6 converters
31 @param ip: IPv4 or IPv6 address
32 @type ip: str
33 """
34 try:
35 return int(binascii.hexlify(socket.inet_aton(ip)), 16)
36 except socket.error:
37 return int(binascii.hexlify(socket.inet_pton(socket.AF_INET6, ip)), 16)
38