当前位置:网站首页>正则过滤内网地址和网段
正则过滤内网地址和网段
2022-04-23 16:40:00 【GokuCode】
1.问题描述
我要过滤出ABC类内网地址和CIDR格式的内网IP段
主要是以下段
1.A类地址:10.0.0.0~10.255.255.255
2.B类地址:172.16.0.0 ~172.31.255.255
3.C类地址:192.168.0.0~192.168.255.255
2.解决问题
正则表达式:
^(10\.\d{
1,3}\.\d{
1,3}\.((0\/([89]|1[0-9]|2\d|3[012]))|(\d{
1,3})))|(172\.(1[6789]|2\\d|3[01])\.\d{
1,3}\.\d{
1,3}(\/(1[6789]|2\d|3[012]))?)|(192\.168\.\d{
1,3}\.\d{
1,3}(\/(1[6789]|2\d|3[012]))?)$
Python举例
# ABC类内网地址检测
def check_intranet_ip_segment(ip):
''' 匹配 1.A类地址:10.0.0.0~10.255.255.255 2.B类地址:172.16.0.0~172.31.255.255 3.C类地址:192.168.0.0~192.168.255.255 匹配成功返回True,反之False '''
result = re.match(r'^(10\.\d{1,3}\.\d{1,3}\.((0\/([89]|1[0-9]|2\d|3[012]))|(\d{1,3})))|(172\.(1[6789]|2\\d|3[01])\.\d{1,3}\.\d{1,3}(\/(1[6789]|2\d|3[012]))?)|(192\.168\.\d{1,3}\.\d{1,3}(\/(1[6789]|2\d|3[012]))?)$', ip)
if result:
return True
else:
return False
版权声明
本文为[GokuCode]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_44331765/article/details/124324451
边栏推荐
- 计组 | 【七 输入/输出系统】知识点与例题
- Hyperbdr cloud disaster recovery v3 Release of version 3.0 | upgrade of disaster recovery function and optimization of resource group management function
- 05 Lua control structure
- G008-HWY-CC-ESTOR-04 华为 Dorado V6 存储仿真器配置
- ◰GL-阴影贴图核心步骤
- ByteVCharts可视化图表库,你想要的我都有
- JSP learning 1
- Oracle data pump usage
- 299. Number guessing game
- Query the data from 2013 to 2021, and only query the data from 2020. The solution to this problem is carried out
猜你喜欢

Set the color change of interlaced lines in cells in the sail software and the font becomes larger and red when the number is greater than 100

English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)

100 deep learning cases | day 41 - convolutional neural network (CNN): urbansound 8K audio classification (speech recognition)

Summary according to classification in sail software

Change the icon size of PLSQL toolbar

阿里研发三面,面试官一套组合拳让我当场懵逼

Kunteng full duplex digital wireless transceiver chip kt1605 / kt1606 / kt1607 / kt1608 is suitable for interphone scheme

The font of the soft cell changes color

MySQL master-slave synchronization pit avoidance version tutorial

On the security of key passing and digital signature
随机推荐
LVM与磁盘配额
力扣-198.打家劫舍
100 deep learning cases | day 41 - convolutional neural network (CNN): urbansound 8K audio classification (speech recognition)
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
Interview question 17.10 Main elements
Gartner publie une étude sur les nouvelles technologies: un aperçu du métacosme
DDT + Excel for interface test
Sail soft calls the method of dynamic parameter transfer and sets parameters in the title
关于 background-image 渐变gradient()那些事!
Oak-d raspberry pie cloud project [with detailed code]
ACL 2022 | DialogVED:用于对话回复生成的预训练隐变量编码-解码模型
Set the color change of interlaced lines in cells in the sail software and the font becomes larger and red when the number is greater than 100
Hyperbdr cloud disaster recovery v3 Version 2.1 release supports more cloud platforms and adds monitoring and alarm functions
Use itextpdf to intercept the page to page of PDF document and divide it into pieces
JIRA screenshot
The most detailed knapsack problem!!!
Sail soft implements a radio button, which can uniformly set the selection status of other radio buttons
文件系统读写性能测试实战
[pyGame games] how did angry birds, a mobile game that became popular all over the world 10 years ago, dominate the list? Classic return
最詳細的背包問題!!!