当前位置: 首页 > news >正文

医院网站解决方案网站网页区别是什么

医院网站解决方案,网站网页区别是什么,辽宁省工程建设信息网,班级的网站设计怎么做用python统计交换机有多少端口UP 用python统计交换机有多少端口UP#xff0c;可以间接的反馈有多少个用户在线。我们使用上次的脚本将可达的网络设备ip统计到reachable_ip.txt中#xff0c;这次我们使用reachable_ip.txt来登陆设备来统计多少端口是UP的 云配置 拓扑 交换机…用python统计交换机有多少端口UP 用python统计交换机有多少端口UP可以间接的反馈有多少个用户在线。我们使用上次的脚本将可达的网络设备ip统计到reachable_ip.txt中这次我们使用reachable_ip.txt来登陆设备来统计多少端口是UP的 云配置 拓扑 交换机配置SSH aaalocal-user admin password cipher Huawei123 //创建python用户密码为123local-user admin privilege level 15local-user admin service-type ssh # user-interface vty 0 4authentication-mode aaaprotocol inbound ssh # stelnet server enable ssh user admin authentication-type all ssh user admin service-type all ssh client first-time enable这个时候我们就能与交换机互访并SSH登陆了 目的 用python统计交换机有多少端口UP可以间接的反馈有多少个用户在线。 代码 使用以下代码统计出有多少IP是可达的他会统计后写入到一个文本文件中也可以自己手动写或者写个循环 import pythonping # 导入 pythonping 库用于执行 ping 操作 import os # 导入 os 库用于操作文件和系统功能# 如果名为 reachable_ip.txt 的文件存在删除它 if os.path.exists(reachable_ip.txt):os.remove(reachable_ip.txt)ip_list range(2, 6) # 创建一个IP列表# 遍历IP列表 for ip in ip_list:ip 192.168.56. str(ip) # 构建IP地址ping_result pythonping.ping(ip) # 执行ping操作f open(reachable_ip.txt, a) # 打开 reachable_ip.txt 文件以追加模式写入if Reply in str(ping_result): # 检查ping结果中是否包含 Replyprint(ip is reachable.) # 如果包含 Reply打印IP地址是可达的f.write(ip \n) # 将可达的IP地址写入 reachable_ip.txt 文件中else:print(ip is not reachable.) # 如果不包含 Reply打印IP地址是不可达的f.close() # 关闭文件 192.168.56.2 is reachable. 192.168.56.3 is reachable. 192.168.56.4 is reachable. 192.168.56.5 is reachable.Process finished with exit code 0#检测到这些IP是可达的我们接下来用另外一个脚本去登陆上去进行统计正式统计交换机端口UP的数量的代码 import paramiko # 导入 paramiko 库用于 SSH 连接 import time # 导入 time 库用于添加延迟等待 import re # 导入 re 库用于正则表达式操作 import datetime # 导入 datetime 库用于处理日期和时间 import socket # 导入 socket 库用于网络通信# 获取用户名和密码 username input(Username: ) # 输入用户名 password input(Password: ) # 输入密码# 获取当前日期和时间 now datetime.datetime.now() date %s-%s-%s % (now.month, now.day, now.year) # 获取当前日期 time_now %s-%s-%s % (now.hour, now.minute, now.second) # 获取当前时间switch_with_tacacs_issue [] # 存储 TACACS 认证失败的交换机列表 switch_not_reachable [] # 存储不可达的交换机列表 total_number_of_up_port 0 # 统计所有已连接的端口数量# 读取可访问的 IP 地址列表文件 with open(reachable_ip.txt) as iplist:number_of_switch len(iplist.readlines()) # 计算交换机数量total_number_of_ports number_of_switch * 24 # 计算总端口数量每台交换机有24个端口iplist.seek(0) # 重置文件指针到文件开头for line in iplist.readlines(): # 逐行读取 IP 地址列表try:ip line.strip() # 去除行末尾的换行符得到IP地址字符串ssh_client paramiko.SSHClient() # 创建 SSHClient 对象ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # 设置自动添加主机密钥ssh_client.connect(hostnameip, usernameusername, passwordpassword) # SSH 连接到交换机print(\nYou have successfully connected to , ip) # 打印成功连接的消息command ssh_client.invoke_shell() # 创建交互式 shellcommand.send(bscreen-length 0 temporary\n) # 发送命令设置命令行分页为0command.send(bdisplay interface brief | include up\n) # 发送命令显示已启用的端口time.sleep(1) # 等待1秒确保命令执行完毕output command.recv(65535) # 接收命令输出print(output.decode(ascii)) # 打印交换机输出search_up_port re.findall(rGigabitEthernet, output.decode(utf-8)) # 用正则表达式匹配已启用的端口number_of_up_port len(search_up_port) # 计算已连接端口数量print(ip has str(number_of_up_port) ports up.) # 打印已连接端口数量信息total_number_of_up_port number_of_up_port # 更新总的已连接端口数量except paramiko.ssh_exception.AuthenticationException: # 处理认证异常print(TACACS is not working for ip .) # 打印 TACACS 认证失败消息switch_with_tacacs_issue.append(ip) # 将无法通过 TACACS 认证的交换机加入列表except socket.error: # 处理网络异常print(ip is not reachable.) # 打印不可达消息switch_not_reachable.append(ip) # 将不可达的交换机加入列表iplist.close() # 关闭 IP 地址列表文件# 输出统计信息print(\n)print(There are totally str(total_number_of_ports) ports available in the network.)print(str(total_number_of_up_port) ports are currently up.)print(port up rate is %.2f%% % (total_number_of_up_port / float(total_number_of_ports) * 100))print(\nTACACS is not working for below switches: )for i in switch_with_tacacs_issue:print(i)print(\nBelow switches are not reachable: )for i in switch_not_reachable:print(i)# 将结果写入文件f open(date .txt, a)f.write(AS of date time_now)f.write(\n\nThere are totally str(total_number_of_ports) ports available in the network.)f.write(\n str(total_number_of_up_port) ports are currently up.)f.write(\nport up rate is %.2f%% % (total_number_of_up_port / float(total_number_of_ports) * 100))f.write(\n***************************************************************\n\n)f.close() # 关闭文件 结果 Username: admin Password: Huawei123You have successfully connected to 192.168.56.2Info: The max number of VTY users is 5, and the numberof current VTY users on line is 1.The current login time is 2023-12-09 23:08:19. Huaweiscreen-length 0 temporary Info: The configuration takes effect on the current user terminal interface only. Huaweidisplay interface brief | include up PHY: Physical *down: administratively down (l): loopback (s): spoofing (b): BFD down (e): ETHOAM down (dl): DLDP down (d): Dampening Suppressed InUti/OutUti: input utility/output utility Interface PHY Protocol InUti OutUti inErrors outErrors GigabitEthernet0/0/1 up up 0% 0% 0 0 GigabitEthernet0/0/2 up up 0% 0% 0 0 GigabitEthernet0/0/3 up up 0% 0% 0 0 NULL0 up up(s) 0% 0% 0 0 Vlanif1 up up -- -- 0 0 Huawei 192.168.56.2 has 3 ports up.You have successfully connected to 192.168.56.3Info: The max number of VTY users is 5, and the numberof current VTY users on line is 1.The current login time is 2023-12-09 23:08:21. Huaweiscreen-length 0 temporary Info: The configuration takes effect on the current user terminal interface only. Huaweidisplay interface brief | include up PHY: Physical *down: administratively down (l): loopback (s): spoofing (b): BFD down (e): ETHOAM down (dl): DLDP down (d): Dampening Suppressed InUti/OutUti: input utility/output utility Interface PHY Protocol InUti OutUti inErrors outErrors GigabitEthernet0/0/1 up up 0% 0% 0 0 GigabitEthernet0/0/2 up up 0% 0% 0 0 GigabitEthernet0/0/3 up up 0% 0% 0 0 GigabitEthernet0/0/4 up up 0% 0% 0 0 NULL0 up up(s) 0% 0% 0 0 Vlanif1 up up -- -- 0 0 Huawei 192.168.56.3 has 4 ports up.You have successfully connected to 192.168.56.4Info: The max number of VTY users is 5, and the numberof current VTY users on line is 1.The current login time is 2023-12-09 23:08:23. Huaweiscreen-length 0 temporary Info: The configuration takes effect on the current user terminal interface only. Huaweidisplay interface brief | include up PHY: Physical *down: administratively down (l): loopback (s): spoofing (b): BFD down (e): ETHOAM down (dl): DLDP down (d): Dampening Suppressed InUti/OutUti: input utility/output utility Interface PHY Protocol InUti OutUti inErrors outErrors GigabitEthernet0/0/1 up up 0% 0% 0 0 GigabitEthernet0/0/2 up up 0% 0% 0 0 NULL0 up up(s) 0% 0% 0 0 Vlanif1 up up -- -- 0 0 Huawei 192.168.56.4 has 2 ports up.You have successfully connected to 192.168.56.5Info: The max number of VTY users is 5, and the numberof current VTY users on line is 1.The current login time is 2023-12-09 23:08:25. Huaweiscreen-length 0 temporary Info: The configuration takes effect on the current user terminal interface only. Huaweidisplay interface brief | include up PHY: Physical *down: administratively down (l): loopback (s): spoofing (b): BFD down (e): ETHOAM down (dl): DLDP down (d): Dampening Suppressed InUti/OutUti: input utility/output utility Interface PHY Protocol InUti OutUti inErrors outErrors GigabitEthernet0/0/1 up up 0% 0% 0 0 GigabitEthernet0/0/2 up up 0% 0% 0 0 GigabitEthernet0/0/3 up up 0% 0% 0 0 GigabitEthernet0/0/4 up up 0% 0% 0 0 GigabitEthernet0/0/5 up up 0% 0% 0 0 NULL0 up up(s) 0% 0% 0 0 Vlanif1 up up -- -- 0 0 Huawei 192.168.56.5 has 5 ports up.There are totally 96 ports available in the network. 14 ports are currently up. port up rate is 14.58%TACACS is not working for below switches: Below switches are not reachable: Process finished with exit code 0 执行完后会生成一个以日期为命名的文本文档
http://www.zqtcl.cn/news/862481/

相关文章:

  • 微站图片临淄信息网招聘最新信息
  • 投诉举报网站建设方案宠物网站 模板
  • 生小孩去什么网站做登记有特点的个人网站
  • 汉中市住房和城乡建设局网站学网站建设需要什么
  • 深圳网站建设外包公司排名网络引流怎么做啊?
  • 关于做暧暧的网站php 网站授权
  • 网站上添加子栏目wordpress群组
  • 一站式手机网站制作有没有代做ppt的网站
  • 西安火车站网站建设网站的设计需要什么
  • 弹幕网站开发代码欧洲人喜欢什么样的服务器
  • 有哪些做壁纸的网站好ftp如何备份网站
  • 网站如何推广出去wordpress foopen
  • 网站空格键代码台州椒江网站建设公司
  • node 网站开发 视频教程汉阳网站推广
  • 广西新农村建设工作专题网站怎样创建公司网站
  • 中国十大招商平台谷歌优化软件
  • 做任务领黄钻的网站中国采购网招标公告
  • 网站建设三层架构实训报告德阳市网站建设
  • 有免费建网站opencms wordpress
  • 行业网站做的好的wordpress要有数据库
  • 重庆智能网站建设哪里好怎么在微信做企业网站
  • 甘肃建设局网站丰都网站建设公司
  • 四川建设设计公司网站网站建设好的图片
  • 建设旅游网站的总结做网站链接怎么做
  • 深圳网站建设建设wordpress cms 布局
  • 企业网站的建立必要性公司建网站哪家
  • 自己做的旅游网站 介绍免费的网站推广在线推广
  • 阿里巴巴 网站设计龙华建设网站公司
  • 番禺网站优化手机商城是什么意思
  • 如何做网站关键词wordpress安装卡死