本文实例讲述了Python实现的根据IP地址计算子网掩码位数功能。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
|
#!/usr/bin/env python
# coding:utf-8
#!/bin/bash
netmask = '255.255.255.0'
result = ""
print netmask
for num in netmask.split( '.' ):
temp = str ( bin ( int (num)))[ 2 :]
result = result + temp
print len ("".join( str (result).split( '0' )[ 0 : 1 ]))
|
运行结果:
希望本文所述对大家Python程序设计有所帮助。
原文链接:https://blog.csdn.net/petrel2015/article/details/78807857