2012年12月28日 星期五

[Python] How to telnet Machine by using Python - 20121229

#! /usr/bin/env python

# -*- coding: utf-8 -*-

# html_converter version 1.0



import time

import getpass

import telnetlib

import sys

import re

from string import *





HOST = "192.168.0.1"

user = "happy2200"

password = "happy2200"

en_password = "happy"





TELNET_PROMPT = "$ "

NEWLINE = "\r\n"



def printRead(texte):

    print texte



tn = telnetlib.Telnet(HOST)



tn.read_until("happy-119 login: ")

tn.write(user + "\r")

if password:

    tn.read_until("Password: ")

    tn.write(password + "\r")



tn.read_until("happy-119>")

tn.write('en' + "\r")



if password:

    tn.read_until("Password: ")

    tn.write(en_password + "\r")





printRead(tn.read_until("happy-119#"))

tn.write('scm' + NEWLINE )

time.sleep(1)

ret = tn.read_very_eager()

print ret



tn.close()

Related Posts:

0 意見:

張貼留言