当前位置: 首页 > 工具软件 > ipaddr-py > 使用案例 >

python ipaddr_python 3:ipaddr/netaddr模块

佟云
2023-12-01

我一定是做错了什么。。。我目前正在尝试使用内置模块验证ip是否在特定子网中。

我正在使用activepython:ActivePython 3.1.2.3 (ActiveState Software Inc.) based on

Python 3.1.2 (r312:79147, Mar 22 2010, 12:20:29) [MSC v.1500 32 bit (Intel)] on win32

在变更日志中有这个:Python News

(editors: check NEWS.help for information about editing NEWS using ReST.)

What's New in Python 3.1.2?

Release date: 2010-03-20

----- snip -----

Removed the ipaddr module.

Issue #3613: base64.{encode,decode}string are now called

System Message: WARNING/2 (, line 706)

----- snip -----

Issue #3959: The ipaddr module has been added to the standard library. Contributed by Google.

这和其他谷歌搜索让我相信ipaddr是内置的,但是:>>> import ipaddr

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named ipaddr

>>> from ipaddr import *

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named ipaddr

所以我想我会安装netaddr并尝试使用它,我从netaddr得到的只有:>>> import netaddr

Traceback (most recent call last):

File "", line 1, in

File "C:\Python31\lib\site-packages\netaddr\__init__.py", line 18, in

from netaddr.ip import IPAddress, IPNetwork, IPRange, all_matching_cidrs, \

File "C:\Python31\lib\site-packages\netaddr\ip\__init__.py", line 1877, in

IPV6_LOOPBACK = IPAddress('::1')

File "C:\Python31\lib\site-packages\netaddr\ip\__init__.py", line 262, in __init__

self.value = addr

File "C:\Python31\lib\site-packages\netaddr\ip\__init__.py", line 292, in _set_value

% value)

netaddr.core.AddrFormatError: failed to detect IP version: '::1'

我感到相当沮丧,我不知道从这里去哪里。。。建议?

 类似资料: