Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- user@host:~/$ cat test.py
- #!/usr/bin/env python
- import paramiko, time
- RECEIVE_BUFFER_SIZE = 99999
- CUR = None
- class Switch:
- def __init__(self, ip, username, password):
- self.ip = str(ip)
- self.username = username
- self.password = password
- # Establish SSH connection
- try:
- self.connection = paramiko.SSHClient()
- self.connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- self.connection.connect(self.ip, username=self.username, password=self.password)
- except paramiko.SSHException, reason:
- print "Could not connect to host %s, reason: %s" %(self.ip, reason)
- self.enabled = False
- return
- except EOFError, reason:
- print "Host %s disconnected, reason: %s" %(self.ip, reason)
- self.enabled = False
- return
- # Create channel
- self.channel = self.connection.invoke_shell()
- buffer = ''
- while not buffer.endswith('>'):
- resp = self.channel.recv(RECEIVE_BUFFER_SIZE)
- buffer += resp
- def test(self):
- self.channel.send("show version")
- self.channel.send("\n")
- buffer = ""
- while "e" not in buffer:
- resp = self.channel.recv(RECEIVE_BUFFER_SIZE)
- buffer += resp
- time.sleep(0.1)
- print buffer
- if __name__ == "__main__":
- s = Switch( "10.1.1.1", "admin", "password" )
- s.test()
- user@host:~/$ python test.py
- show version
- Dell Force10 Networks Real Time Operating System Software
- Dell Force10 Operating System Version: 1.0
- Dell Force10 Application Software Version: 8.4
- Copyright (c) 1999-2011 by Dell Inc.
- Build Time: Tue Nov 15 09:32:07 2011
- E600i uptime is 3 year(s), 3 week(s), 4 day(s), 11 hour(s), 31 minute(s)
- (truncated for brevity)
- user@host:~/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement