国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現根據IP地址和子網掩碼算出網段的方法

2019-11-25 17:06:41
字體:
來源:轉載
供稿:網友

本文實例講述了Python實現根據IP地址和子網掩碼算出網段的方法。分享給大家供大家參考。具體如下:

該代碼在Linux環境2.6.6python版本測試通過!

#!/usr/bin/env python#_*_encoding:utf-8_*_#Input your ip address and netmask to figure out your network .#申明:此腳本為交互式,默認情況下請執行python network.pyfrom IPy import IPinput_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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 文化| 江陵县| 永和县| 行唐县| 深圳市| 建湖县| 酒泉市| 灵台县| 涞源县| 阿拉善右旗| 珠海市| 安阳县| 池州市| 东丽区| 泾源县| 崇左市| 崇义县| 固原市| 赤峰市| 荣昌县| 连山| 蒙阴县| 彰化市| 丽水市| 巧家县| 大方县| 搜索| 安溪县| 黄梅县| 碌曲县| 子长县| 关岭| 滨州市| 家居| 车致| 江山市| 舟曲县| 凉城县| 江源县| 福建省| 且末县|