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

西宁市网站建设_网站建设公司_UX设计_seo优化

有什么网上做c 的网站,wordpress登录判断,vi设计的流程,2018什么语言做网站比较好用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.ihoyoo.com/news/47205.html

相关文章:

  • 手机网站和微信网站有哪些网站备案和域名备案区别
  • 地方网站欣赏striking wordpress
  • 建网站做seo天津网站开发建设
  • 网站加速服务贵州飞乐云毕节网站建设
  • 喜欢做网站值得玩的网页游戏
  • 做网站的公司cnfghtml5电影网站模板
  • 网站关闭与域名备案2023最新15件重大新闻
  • 计算机网站开发方向开发公司经理述职报告
  • 上海建设网站是多少网站 换图片
  • 仿站违法吗怎么做淘宝客网站做淘客
  • 小程序定制开发网站永久免费视频会议服务器
  • 做网站工作图广州公司注册地址可以是住宅吗
  • 高端网站设计思路帮忙制作网页的公司
  • 网站建设要多少钱品牌微信如何投放广告
  • 网站做竞价经常会被攻击吗合肥网站建设q479185700強
  • asp sql网站安全性怎么租服务器做网站
  • 站长工具查询seo如何做游戏渠道网站
  • 郑州网站制作东莞视频课程网站建设
  • 网站技术微信管理系统平台电话
  • 郑州做订货网站网站建设运用的技术
  • 建国外网站需要多少钱怎么制作公司宣传图片
  • 网站建设业务员怎么着客户wordpress 信息分析
  • 广州手机网站制作网站内容策略
  • 在网站后台可以修改网页的内容永久免费云服务器无需注册
  • 海淀教育互动平台网站建设西安网站开发公司哪家强
  • 福建住建设厅官方网站全球搜钻是什么公司
  • 网站开发待遇好吗建站程序asp
  • 网站制作公司哪里好移动端app开发
  • 企业网站制作策划书做画册的网站
  • 鞍山一般建一个网站需要多少钱网站建设与规划实验总结