当前位置:网站首页>正则过滤内网地址和网段
正则过滤内网地址和网段
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
边栏推荐
- 博士申请 | 厦门大学信息学院郭诗辉老师团队招收全奖博士/博后/实习生
- The font of the soft cell changes color
- The most detailed Backpack issues!!!
- Sail soft calls the method of dynamic parameter transfer and sets parameters in the title
- 无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
- ◰GL-着色器处理程序封装
- 如何建立 TikTok用户信任并拉动粉丝增长
- How to upgrade openstack across versions
- vim编辑器的实时操作
- English | day15, 16 x sentence true research daily sentence (clause disconnection, modification)
猜你喜欢
文件操作详解(2)
众昂矿业:萤石浮选工艺
各大框架都在使用的Unsafe类,到底有多神奇?
ACL 2022 | DialogVED:用于对话回复生成的预训练隐变量编码-解码模型
Hypermotion cloud migration helped China Unicom. Qingyun completed the cloud project of a central enterprise and accelerated the cloud process of the group's core business system
Hyperbdr cloud disaster recovery v3 Version 2.1 release supports more cloud platforms and adds monitoring and alarm functions
The solution of not displaying a whole line when the total value needs to be set to 0 in sail software
Use if else to judge in sail software - use the title condition to judge
1959年高考数学真题
漫画:什么是IaaS、PaaS、SaaS?
随机推荐
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
Sort by character occurrence frequency 451
Nacos detailed explanation, something
深入了解3D模型相关知识(建模、材质贴图、UV、法线),置换贴图、凹凸贴图与法线贴图的区别
loggie 源码分析 source file 模块主干分析
Selenium IDE and XPath installation of chrome plug-in
5分钟NLP:Text-To-Text Transfer Transformer (T5)统一的文本到文本任务模型
MySQL personal learning summary
Day 10 abnormal mechanism
∑GL-透视投影矩阵的推导
Use case execution of robot framework
Detailed explanation of gzip and gunzip decompression parameters
Pycham connects to the remote server and realizes remote debugging
04 Lua operator
Report FCRA test question set and answers (11 wrong questions)
漫画:什么是IaaS、PaaS、SaaS?
05 Lua 控制结构
RecyclerView advanced use - to realize drag and drop function of imitation Alipay menu edit page
Gartner publie une étude sur les nouvelles technologies: un aperçu du métacosme
Day 9 static abstract class interface