Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

telnet python

def telnet_connect(hostname, username, password):
    t = telnetlib.Telnet(hostname)            # actively connects to a telnet server
    # t.set_debuglevel(1)                     # uncomment to get debug messages
    t.read_until(b'login:', 10)               # waits until it recieves a string 'login:'
    t.write(username.encode('utf-8'))         # sends username to the server
    t.write(b'
')                            # sends return character to the server
    t.read_until(b'Password:', 10)            # waits until it recieves a string 'Password:'
    t.write(password.encode('utf-8'))         # sends password to the server
    t.write(b'
')                            # sends return character to the server
    n, match, previous_text = t.expect([br'Login incorrect', br'$'], 10)
    if n == 0:
        print('Username and password failed - giving up')
    else:
        t.write(b'exec ps aux
')             # sends a command to the server
        t.write(b'exec exit
')
        print(t.read_all().decode('utf-8'))  # read until socket closes
    t.close()

if __name__ == '__main__':
    if len(sys.argv) < 2: 
        print "Usage: python telnet_login.py hostname username"
    hostname = sys.argv[1]
    username = sys.argv[2]
    password = getpass.getpass('Password: ')
    telnet_connect(hostname, username, password)
    
Comment

PREVIOUS NEXT
Code Example
Python :: set dtype for multiple columns pandas 
Python :: real time crypto prices python 
Python :: remove a char in a string python 
Python :: Creating virtual environments 
Python :: what day i s it 
Python :: how to input comma separated int values in python 
Python :: find index of pandas column 
Python :: django modelform style 
Python :: python webdriver open with chrome extension 
Python :: dataframe print column comma separated 
Python :: instagram private account hacking code python 
Python :: make calculator in python 
Python :: read pdf py 
Python :: create dictionary comprehension python 
Python :: python get methods of object 
Python :: check nan values in a np array 
Python :: string to datetime python 
Python :: dataframe fillna with 0 
Python :: export_excel file python 
Python :: python list of all characters 
Python :: initialize an array in python 
Python :: django jalali date 
Python :: python sqlite dict 
Python :: how to make custom buttons tkinter 
Python :: how to keep a webdriver tab open 
Python :: convert pandas column type 
Python :: python get path of current file 
Python :: how to generate random normal number in python 
Python :: jupyter lab 
Python :: declare numpy zeros matrix python 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =