python---IPy

來源:互聯網
上載者:User

標籤:類型   包含   網路   python   5.0   imp   解析   net   重疊   

Python第三方模組IPy,可完成高效的IP規劃工作

#安裝#pip3 install IPy#最新版本V0.83
IP地址 網段的基本處理
>>>from IPy import IP>>>ip = IP(‘192.168.1.25‘)#反向解析地址格式>>>ip.reverseNames()#判斷網路類型,公網或私網>>>ip.iptype()#轉換為整型,十六進位,二進位>>>ip.int()>>>ip.strHex()>>>ip.strBin()
 多網路計算方法
#判斷IP和網段是否包含有另一網段>>>‘192.168.1.100‘ in IP(‘192.168.1.0/24‘)>>>True#判斷兩個網段是否存在重疊>>>IP(‘192.168.0.0/23‘).overlaps(‘192.168.1.0/24‘)>>>1 #1代表存在重疊>>>IP(‘192.168.0.0/24‘).overlaps(‘192.168.2.0‘)>>>0 #0代表不存在重疊
#!/usr/bin/env python# -*- coding:utf-8 -*-#Author: CCoo2from IPy import IPip_s = input("請輸入IP地址,或網段地址:")ips = IP(ip_s)if len(ips) > 1: #為1個網路地址    print("網路地址: %s" % ips.net())    print("網路遮罩地址: %s" % ips.netmask())    print("廣播位址: %s" % ips.broadcast())    print("地址反向解析: %s" % ips.reverseNames()[0])    print("網路子網數: %s" % len(ips))else:#為1個IP地址    print("IP反向解析: %s" % ips.reverseNames()[0])print("十六進位地址:%s" % ips.strHex())print("二進位地址: %s" % ips.strBin())print("地址類型: %s" % ips.iptype())‘‘‘請輸入IP地址,或網段地址:192.168.1.1IP反向解析: 1.1.168.192.in-addr.arpa.十六進位地址:0xc0a80101二進位地址: 11000000101010000000000100000001地址類型: PRIVATE#####################################請輸入IP地址,或網段地址:192.168.2.0/24網路地址: 192.168.2.0網路遮罩地址: 255.255.255.0廣播位址: 192.168.2.255地址反向解析: 2.168.192.in-addr.arpa.網路子網數: 256十六進位地址:0xc0a80200二進位地址: 11000000101010000000001000000000地址類型: PRIVATE‘‘‘

  

python---IPy

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.