Python实现的根据IP地址计算子网掩码位数功能示例
作者:petrel2015 时间:2021-08-30 21:21:31
本文实例讲述了Python实现的根据IP地址计算子网掩码位数功能。分享给大家供大家参考,具体如下:
#!/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]))
运行结果:
PS:这里再为大家推荐几款相关在线工具供大家参考:
在线网络计算器|TCP/IP子网掩码计算与换算工具:
http://tools.jb51.net/aideddesign/ipcalc
在线IP地址/子网掩码计算与转换工具:
http://tools.jb51.net/aideddesign/ip_net_calc
在线子网掩码换算与网络计算工具:
http://tools.jb51.net/aideddesign/network_calc
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/petrel2015/article/details/78807857
标签:Python,IP地址,子网掩码
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
对Python发送带header的http请求方法详解
2022-02-06 11:44:59
python使用Plotly绘图工具绘制散点图、线形图
2022-06-24 08:11:50
![](https://img.aspxhome.com/file/2023/7/78607_0s.png)
学生信息管理系统python版
2023-10-17 07:32:34
python使用协程实现并发操作的方法详解
2021-09-24 11:23:10
python分布式环境下的限流器的示例
2023-07-11 19:25:38
Pycharm远程连接服务器并实现代码同步上传更新功能
2023-09-20 04:44:40
![](https://img.aspxhome.com/file/2023/7/76117_0s.jpg)
python爬虫将js转化成json实现示例
2021-10-20 15:32:31
![](https://img.aspxhome.com/file/2023/0/80640_0s.png)
在python中使用xlrd获取合并单元格的方法
2023-09-09 17:00:43
基于PyQt5自制简单的文件内容检索小工具
2023-06-11 19:45:03
![](https://img.aspxhome.com/file/2023/0/59830_0s.png)
网马解密大讲堂——网马解密中级篇(Document.write篇)
2009-09-16 16:16:00
python3实现带多张图片、附件的邮件发送
2023-05-11 06:51:10
Python实现简单的"导弹" 自动追踪原理解析
2021-04-15 05:48:27
![](https://img.aspxhome.com/file/2023/9/110549_0s.png)
python实现大转盘抽奖效果
2023-12-16 13:50:30
![](https://img.aspxhome.com/file/2023/1/72081_0s.jpg)
Python简单定义与使用字典dict的方法示例
2023-03-10 03:22:48
![](https://img.aspxhome.com/file/2023/8/93668_0s.jpg)
Python获取江苏疫情实时数据及爬虫分析
2022-09-19 02:12:30
![](https://img.aspxhome.com/file/2023/9/95439_0s.jpg)
pandas中的DataFrame按指定顺序输出所有列的方法
2022-11-04 16:24:02
Python lxml模块安装教程
2021-08-26 22:23:43
python paramiko模块学习分享
2021-11-10 16:57:00
python与xml数据的交互详解
2021-09-12 06:54:10
![](https://img.aspxhome.com/file/2023/1/99681_0s.png)
框架和框架之间的关系
2008-01-17 18:54:00
![](https://img.aspxhome.com/file/UploadPic/20081/17/2008117185848873s.jpg)