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