Python's computational-ipy on IP

Source: Internet
Author: User

At work, we sometimes encounter the need to calculate whether an IP or network segment is in another network segment. Sometimes it is judged whether the two segments overlap. This is a lot easier to use ipy.

The following shell is the installation of ipy:

Cd/usr/localwget IPY-0.81.TAR.GZCD Ipy-0.81python Install

The convenience of Ipy:

1:ip (' '). Version () #获取IP的类型


ip = IP (' ') print Ip.len () #有多少个ipfor x in Ip:print (x) #分别打印出每个ip


IP (' '). Iptype () #ip的类型IP (' '). Int () #转换成整形IP (' '). Strhex () #转换成十六进制IP (' '). Strbin () # Convert to binary print (IP (0x8080808)) #十六进制转换成ip


IP (' '). Strnormal (1) #输出/24 format IP (' '). Strnormal (2) #输出掩码格式IP (' '). Strnormal (3) #输出广播地址格式


IP (' ') in IP (' ') # is inside the bit


IP (' '). overlaps (' ') #网段不存在重叠 returns 0 (returns 0 if overlapping)

Through the above record, we can solve the problem in the work is: batch to determine the type of IP, the bulk of the IP into their desired format, batch to determine whether an IP is included in a network segment, in batches to determine whether there is overlap between two network segments.

This article is from the "Zhangweihong" blog, make sure to keep this source

Python's computational-ipy on IP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.