Python脚本查看思科设备的接口

记录利用Python脚本查看思科设备的接口。

#!/usr/bin/env python
import paramiko
import sys
import time
 
class CiscoSwitch():
         def __init__(self,host,username,password):
                  self.username  = username
                  self.host      = host
                  self.password  = password
 
         def Login(self):
                  self.child = paramiko.SSHClient()
                  self.child.set_missing_host_key_policy(paramiko.AutoAddPolicy())
                  self.child.connect(self.host,username=self.username,password=self.password)
                  self.remote = self.child.invoke_shell()
        
        def showcmd(self,cmd):
                 print "[+] Connect to Router..."
                 self.remote.send("\n")
                 self.remote.send(cmd)
                 time.sleep(0.5)
                 output = self.remote.recv(5000)
                 print output
 
if __name__ == '__main__':
       print "[+] This Program is beging done..."
       for ip in open("/opt/other/ip.txt"):
            Switch = CiscoSwitch(ip,'admin','Password.123')
            Switch.Login()
            Switch.showcmd("show ip int brief\n")

原文地址:http://blog.51cto.com/arckyli/2065313

时间: 2024-08-27 12:05:56

Python脚本查看思科设备的接口的相关文章

利用python脚本和telnet调试dubbo接口

原文地址:https://hhyo.github.io/2017/10/20/python-dubbo-telnet/ 最近在测试项目中接触到dubbo框架,由于业务逻辑复杂,前台一个业务流程在后端会依赖多个服务提供数据,而各方开发进度也不完全一致.在业务测试脚本编写完成后,希望能够在项目整体提测前,先验证部分已提供的dubbo接口的可用性.另外一方面,也能够在测试过程中更快的定位到具体的服务提供者,指派任务,减少反复沟通定位问题所耗费的时间. 先说环境:OS: macOS High Sierr

分析和查看思科设备VTP工作原理和STP生成树原理

实验 拓扑图: zhu 注:VTP分为三种模式(一,server,二,client,三,transparent).每个管理域至少一个server模式,便于创建,删除,修改VLAN.VTP通告的数据帧被发送到组播地址:01-00-0c-cc-cc-cc,是相邻设备都能收到这些帧. VTP的要求: 一,域内每个交换机必须是相同的VTP域名.二,交换机必须是相邻的,相邻的交换机需要相同域名. 三,所有的交换机必须配置为中继链路. VTP的配置: 一,确定VTP版本.二,加入到管理域中,确定它的名称和口

通过python脚本查看端口

[[email protected] alertscripts]# cat check_port1.py #!/usr/bin/env python #coding:utf-8 import os, json port_list=[] port_dict={"data":None} cmd='''''ss -tnlp|egrep -i "$1"|awk {'print $4'}|awk -F':' '{if ($NF~/^[0-9]*$/) print $NF}'|

Linux服务器CPU、内存、磁盘空间、负载情况查看python脚本

网上搜,东拼西凑,组装了一个可以查Linux服务器CPU使用率.内存使用率.磁盘空间占用率.负载情况的python脚本. 脚本内容如下: # -*- coding:utf-8 -*- - import os, time last_worktime=0 last_idletime=0 def get_cpu(): global last_worktime, last_idletime f=open("/proc/stat","r") line=""

查看私有仓库镜像python脚本

1.在python官网下载python解释器 [https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz] 2.解包进入同名目录编译安装 [[email protected] python]#./configure --prefix=/usr/local/python3 3.将python3程序设置软连接 [[email protected] ~]# ln -s /usr/local/python3/bin/python3 /usr/bin

用 Python 脚本实现对 Linux 服务器的监控

hon 分享到:8 原文出处: 曹江华 目前 Linux 下有一些使用 Python 语言编写的 Linux 系统监控工具 比如 inotify-sync(文件系统安全监控软件).glances(资源监控工具)在实际工作中,Linux 系统管理员可以根据自己使用的服务器的具体情况编写一下简单实用的脚本实现对 Linux 服务器的监控. 本文介绍一下使用 Python 脚本实现对 Linux 服务器 CPU 内存 网络的监控脚本的编写. Python 版本说明 Python 是由 Guido va

另外一个给微信企业号发文字信息的python脚本

http://chenx1242.blog.51cto.com/10430133/1954634 文章里面有一个python脚本可以用来给微信企业号发信息,如果你不喜欢那篇文章里面"title+content"的样式,可以使用如下的脚本: #coding:utf-8 import urllib2 import json import sys def getMsg():     #为了避免发送中文消息报错,使用utf8方式编码     reload(sys)     sys.setdef

利用pyinstaller将python脚本打包发布

之前写了一个小工具,将excel配置表转换为json.xml.lua等配置文件.最近在学习egret,正好需要转换配置文件,刚好就用上了.然而当我想把工具拷到工作目录时,就发愁了.之前我为了方便扩展,把程序拆分得太细: [email protected]:~/Documents/code/github/py_exceltools$ ls -lh 总用量 80K drwxrwxr-x 2 xzc xzc 4.0K 7月 27 23:03 bin drwxrwxr-x 2 xzc xzc 4.0K

用python 脚本控制telnet登录交换机

目的:学习用python脚本登录交换机并执行相关操作 环境:windows 7  Python 3.5.3 最初原因是因为工作需要在交换机上查询IP地址的来源端口,不停的跳转查看很麻烦,于是决定写脚本,这里只写关于用Python登录和之后的可用方法. telnet是内置模块,模块名telnetlib. # 定义登录的用户名.密码和登录的设备地址 username = 'abc' password = '123' switch_ip = '1.2.3.4' # 连接 tel_con = telne