当前位置:网站首页>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)
边栏推荐
- Executive engine module of high performance data warehouse practice based on Impala
- Vscode setting delete line shortcut [easy to understand]
- 配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
- Global and Chinese markets of stainless steel surgical suture 2022-2028: Research Report on technology, participants, trends, market size and share
- C语言中sprintf()函数的用法
- PhD Debate-11 预告 | 回顾与展望神经网络的后门攻击与防御
- LeetCode 1. Sum of two numbers
- Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
- VMware安装win10镜像
- 关于举办科技期刊青年编辑沙龙——新时代青年编辑应具备的能力及提升策略的通知...
猜你喜欢
Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era
Yolov5 practice: teach object detection by hand
Interview summary of large factories
DGraph: 大规模动态图数据集
【云原生】简单谈谈海量数据采集组件Flume的理解
你想要的宏基因组-微生物组知识全在这(2022.7)
机器学习-感知机模型
Ap和F107数据来源及处理
Atcoder beginer contest 169 (B, C, D unique decomposition, e mathematical analysis f (DP))
⌈ 2022 ⌋ how to use webp gracefully in projects
随机推荐
DigiCert SSL证书支持中文域名申请吗?
john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
Headline | Asian control technology products are selected in the textile and clothing industry digital transformation solution key promotion directory of Textile Federation
Yyds dry goods inventory has not revealed the artifact? Valentine's Day is coming. Please send her a special gift~
数字IC手撕代码--投票表决器
ROW_ NUMBER()、RANK()、DENSE_ Rank difference
jsp 和 servlet 有什么区别?
LeetCode 6. Z 字形变换 (N字形变换)
TCP server communication process (important)
PhD Debate-11 预告 | 回顾与展望神经网络的后门攻击与防御
Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
Cloud native cicd framework: Tekton
Multi task prompt learning: how to train a large language model?
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
Yyds dry goods inventory # look up at the sky | talk about the way and principle of capturing packets on the mobile terminal and how to prevent mitm
Cell: Tsinghua Chenggong group revealed an odor of skin flora. Volatiles promote flavivirus to infect the host and attract mosquitoes
The macrogenome microbiome knowledge you want is all here (2022.7)
Vscode setting delete line shortcut [easy to understand]
sql解决连续登录问题变形-节假日过滤
July 1st gift: Yi Jingjie's "hundred day battle" ended perfectly, and the database of Guiyang bank was sealed in advance