当前位置:网站首页>IP address translation address segment
IP address translation address segment
2022-07-02 16:58:00 【Mingming Ruyue 001】
Recent work needs , Wrote a small script for address conversion , Easy to find the corresponding IP Home address segment , It has a certain auxiliary effect on the operation and maintenance personnel
Some places in the middle can be simplified , But I'm too lazy to change …
as follows :
# coding:utf-8
def transition_to_sub26(file):
with open(file, 'r', encoding='utf-8') as file:
for ip in file:
ip_end = ip.split(".")[3]
ip_end = int(ip_end)
def sub_net(ip_end):
if ip_end < 64:
return "0/26"
elif ip_end < 128:
return "64/26"
elif ip_end < 192:
return "128/26"
else:
return "192/26"
res = sub_net(ip_end)
# print(res)
ip_join = ".".join(ip.split(".")[0:3])
# print(ip_join) #10.41.0
ip_sub = ip_join + "." + res
# return ip_sub
print(ip_sub) # 10.41.0.64/26
with open("IP Address translation results (26 position ).txt", 'a+', encoding='utf-8') as file1:
file1.write(ip_sub + "\n")
def transition_to_sub28(file):
with open(file, 'r', encoding='utf-8') as file:
for ip in file:
ip_end = ip.split(".")[3]
ip_end = int(ip_end)
def sub_net(ip_end):
if ip_end < 16:
return "0/28"
elif ip_end < 32:
return "16/28"
elif ip_end < 48:
return "32/28"
elif ip_end < 64:
return "48/28"
elif ip_end < 80:
return "64/28"
elif ip_end < 96:
return "80/28"
elif ip_end < 112:
return "96/28"
elif ip_end < 128:
return "112/28"
elif ip_end < 144:
return "128/28"
elif ip_end < 160:
return "144/28"
elif ip_end < 176:
return "160/28"
elif ip_end < 192:
return "176/28"
elif ip_end < 208:
return "192/28"
elif ip_end < 224:
return "208/28"
elif ip_end < 240:
return "224/28"
else:
return "240/28"
res = sub_net(ip_end)
# print(res)
ip_join = ".".join(ip.split(".")[0:3])
# print(ip_join) #10.41.0
ip_sub = ip_join + "." + res
print(ip_sub) # 10.41.0.64/26
with open("IP Address translation results (28 position ).txt", 'a+', encoding='utf-8') as file2:
file2.write(ip_sub + "\n")
if __name__ == '__main__':
file = input(" Please enter IP Address file path :" + "\n")
input_result = input(" Please enter the address segment to be converted ,【1】 Means to convert into 26 position ,【2】 Means to convert into 28 position :" + "\n")
if input_result == "1":
transition_to_sub26(file)
if input_result == "2":
transition_to_sub28(file)
边栏推荐
- LeetCode 3. 无重复字符的最长子串
- P6774 [NOI2020] 时代的眼泪(分块)
- 618深度复盘:海尔智家的制胜方法论
- TCP server communication process (important)
- Serial port controls steering gear rotation
- July 1st gift: Yi Jingjie's "hundred day battle" ended perfectly, and the database of Guiyang bank was sealed in advance
- Ap和F107数据来源及处理
- Global and Chinese markets for carbon dioxide laser cutting heads 2022-2028: Research Report on technology, participants, trends, market size and share
- sql解决连续登录问题变形-节假日过滤
- 什么是泛型?- 泛型入门篇
猜你喜欢

机器学习-感知机模型

Lampe respiratoire PWM

亚马逊云科技 Community Builder 申请窗口开启

Unity uses ugui to set a simple multi-level horizontal drop-down menu (no code required)

Unity使用UGUI设置一个简单多级水平方向下拉菜单(不需要代码)

DGraph: 大规模动态图数据集

Cell: Tsinghua Chenggong group revealed an odor of skin flora. Volatiles promote flavivirus to infect the host and attract mosquitoes

上传代码到远程仓库报错error: remote origin already exists.

A week of short video platform 30W exposure, small magic push helps physical businesses turn losses into profits

【云原生】简单谈谈海量数据采集组件Flume的理解
随机推荐
只是巧合?苹果iOS16的神秘技术竟然与中国企业5年前产品一致!
入行数字IC验证后会做些什么?
linux安装postgresql + patroni 集群问题
寒门再出贵子:江西穷县考出了省状元,做对了什么?
Library management system (Shandong Agricultural University Curriculum Design)
大廠面試總結大全
上传代码到远程仓库报错error: remote origin already exists.
La boîte de connexion du hub de l'unit é devient trop étroite pour se connecter
LeetCode 6. Zigzag transformation (n-shaped transformation)
Deep learning image data automatic annotation [easy to understand]
618 deep resumption: Haier Zhijia's winning methodology
P6774 [noi2020] tears in the era (block)
远程办公对我们的各方面影响心得 | 社区征文
VMware安装win10镜像
Just a coincidence? The mysterious technology of apple ios16 is even consistent with the products of Chinese enterprises five years ago!
七一献礼:易鲸捷 “百日会战”完美收官 贵阳银行数据库提前封板
Easy language ABCD sort
Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
Xiaopeng P7 had an accident on rainy days, and the airbag did not pop up. Official response: the impact strength did not meet the ejection requirements
[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array