| OLD | NEW |
| (Empty) |
| 1 # -*- coding: utf-8 -*- | |
| 2 """ | |
| 3 Utility functions. Part of the pygeoip package. | |
| 4 | |
| 5 @author: Jennifer Ennis <zaylea@gmail.com> | |
| 6 | |
| 7 @license: 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 socket | |
| 24 import binascii | |
| 25 | |
| 26 | |
| 27 def ip2long(ip): | |
| 28 """ | |
| 29 Wrapper function for IPv4 and IPv6 converters | |
| 30 @param ip: IPv4 or IPv6 address | |
| 31 @type ip: str | |
| 32 """ | |
| 33 try: | |
| 34 return int(binascii.hexlify(socket.inet_aton(ip)), 16) | |
| 35 except socket.error: | |
| 36 return int(binascii.hexlify(socket.inet_pton(socket.AF_INET6, ip)), 16) | |
| OLD | NEW |