当前位置:网站首页>IP地址转换地址段
IP地址转换地址段
2022-07-02 14:08:00 【明明如月001】
近期工作需要,写了一个地址转化的小脚本,方便找到对应IP归属地址段,对于运维人员有一定辅助作用
中间有些地方可以简化,不过也懒得改了…
如下:
# 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地址转换结果(26位).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地址转换结果(28位).txt", 'a+', encoding='utf-8') as file2:
file2.write(ip_sub + "\n")
if __name__ == '__main__':
file = input("请输入IP地址文件路径:" + "\n")
input_result = input("请输入需要转换的地址段,【1】代表转化为26位,【2】代表转化为28位:" + "\n")
if input_result == "1":
transition_to_sub26(file)
if input_result == "2":
transition_to_sub28(file)
边栏推荐
- 易语言abcd排序
- LeetCode 5. Longest Palindromic Substring
- How to choose the right kubernetes storage plug-in? (09)
- LeetCode 1. 两数之和
- VMware安装win10镜像
- 【云原生】简单谈谈海量数据采集组件Flume的理解
- Atcoder beginer contest 169 (B, C, D unique decomposition, e mathematical analysis f (DP))
- Understand the key technology of AGV -- the difference between laser slam and visual slam
- Bib | graph representation based on heterogeneous information network learning to predict drug disease association
- Detailed explanation of @accessories annotation of Lombok plug-in
猜你喜欢

Kubernetes three open interfaces first sight

According to the atlas of data security products and services issued by the China Academy of information technology, meichuang technology has achieved full coverage of four major sectors

linux下配置Mysql授权某个用户远程访问,不受ip限制

Masa framework - DDD design (1)

基于Impala的高性能数仓实践之执行引擎模块
![john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])

What is the difference between self attention mechanism and fully connected graph convolution network (GCN)?

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

Download blender on Alibaba cloud image station

配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
随机推荐
Yyds dry goods inventory has not revealed the artifact? Valentine's Day is coming. Please send her a special gift~
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
Library management system (Shandong Agricultural University Curriculum Design)
流批一体在京东的探索与实践
618深度复盘:海尔智家的制胜方法论
OpenHarmony如何启动远程设备的FA
LeetCode 6. Zigzag transformation (n-shaped transformation)
LeetCode 5. Longest Palindromic Substring
TCP congestion control details | 2 background
Data security industry series Salon (III) | data security industry standard system construction theme Salon
Résumé de l'entrevue de Dachang Daquan
Exploration and practice of integration of streaming and wholesale in jd.com
PWM breathing lamp
LeetCode 2. 两数相加
P6774 [noi2020] tears in the era (block)
pwm呼吸燈
大廠面試總結大全
Unity Json 编写
有赞和腾讯云、阿里云一同摘得“中国企业云科技服务商50强”[通俗易懂]
Global and Chinese markets of stainless steel surgical suture 2022-2028: Research Report on technology, participants, trends, market size and share