該代碼在Linux環境2.6.6python版本測試通過!
#!/usr/bin/env python #_*_encoding:utf-8_*_ #Input your ip address and netmask to figure out your network . #申明:此腳本為交互式,默認情況下請執行python network.py from IPy import IP input_IP = raw_input('請輸入ip地址:') list1 = input_IP.split('.') if len(list1) != 4: print "您輸入的ip地址不合法,請重新輸入!" exit() for i in list1: if i.isdigit() == True and int(i) >=0 and int(i) <= 255: pass else: print "您輸入的ip地址不合法,請重新輸入!" exit() input_Netmask = raw_input('請輸入子網掩碼:') list2 = input_Netmask.split('.') if len(list2) != 4: print "您輸入的子網掩碼不合法,請重新輸入!" exit() for i in list2: if i.isdigit() == True and int(i) >=0 and int(i) <= 255: pass else: print "您輸入的子網掩碼不合法,請重新輸入!" exit() print "您所在的網段為:%s" % (IP(input_IP).make_net(input_Netmask))
希望本文所述對大家的Python程序設計有所幫助。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com