How to merge IP segments

Source: Internet
Author: User

1. Installing IPY

PIP3 Install IPy

2. Write the script:

[Email protected]:~ $ cat combine_ip.py
From IPy import Ipset, IP
Import Sys

def handler (file_name):
ret = Ipset ()
For IP in Open (file_name):
ip = "%s/24"% (IP)
Ret.add (IP (IP, make_net = True))

For item in RET:
Print (item)

if __name__ = = "__main__":

file_name = sys.argv[1]
Handler (file_name)

3. Start the implementation, obviously has been installed successfully, how to execute the foot of this newspaper wrong?

[Email protected]:~ $ python combine_ip.py
Traceback (most recent):
File "combine_ip.py", line 1, <module>
From IPy import Ipset, IP
Importerror:no module named IPy

4. Where do I find the ipy?

[Email protected]:~ $ sudo find/-name "*ipy*"
Password:
Find:/DEV/FD/3: Not a directory
Find:/DEV/FD/4: Not a directory
/library/frameworks/python.framework/versions/3.4/lib/python3.4/site-packages/__pycache__/ipy.cpython-34.pyc
/library/frameworks/python.framework/versions/3.4/lib/python3.4/site-packages/ipy-0.83-py3.4.egg-info
/library/frameworks/python.framework/versions/3.4/lib/python3.4/site-packages/ipy.py

4. Execute python3.4 combine_ip.py ip.list OK!!

============== Split Line ==============

Http://www.ab126.com/goju/1840.html

>>> from IPcalc Import Network

>>> net = Network (' 10.153.192.0/21 ')

>>> Net.netmask ()

IP(' 255.255.248.0 ')

>>> Net.host_first ()

IP(' 10.153.192.1 ')

>>> Net.host_last ()

IP(' 10.153.199.254 ')

>>> Net.broadcast ()

IP(' 10.153.199.255 ')

How to merge IP segments

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: info-contact@alibabacloud.com 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.