ipaddress的lxml xpath扩展库
lxml-xpath-ipaddress的Python项目详细描述
IP地址的LXML扩展库
此库包含包装python ipaddress库的lxml扩展函数。
有了这个库,您可以使用xpath表达式在xml数据中查找ip项。为了 示例:
fromlxmlimportetreefromlxml_xpath_ipaddressimportip_ns# given "config" is an LXML XML structure, you can run the XPath to find all IPv4 network items:config=etree.parse('tests/config.xml')items=config.xpath('//*[ip:ip4-net(.)',namespaces=ip_ns)print(items[0].text)# >>> 10.10.0.0/16# Find all items that are in either the 172.18/16 or 101.10.201/24 subnetsitems=config.xpath('//*[ip:in-subnet(., "172.18.0.0/16") or ip:in-subnet(., "10.10.201.0/24")]',namespaces=ip_ns)print(items[0].text)# >>> 172.18.1.1
安装
$ pip install lxml-xpath-ipaddress
lxml扩展函数
IPv4或IPv6
- IP任意(值)
- IP净值(值)
- IP主机(值)
IPv4
- IP4任意(值)
- IP4净值
- IP4主机(值)
IPv6
- IP6任意(值)
- IP6净值
- IP6主机(值)
子网检查
- 在子网中(值,子网字符串)
python函数
图书馆也包含这些功能作为通用功能, 以便在其他应用中使用。请参阅模块文档字符串以供使用。