<commit_before><commit_msg>Adding telnet script<commit_after>import telnetlib
import time
import socket
import sys

TELNET_PORT = 23
TELNET_TIMEOUT = 6

# Define remote telnet connection with specified command
def send_command(remote_conn, cmd):
        '''
        strip trailing new-line. 'r' in rstrip means on the end
        lstrip is the beginning. strip does both at beginning and at the end
        '''
        cmd = cmd.rstrip()
        remote_conn.write(cmd + '\n')
        time.sleep(1)
        return remote_conn.read_very_eager()

# Define login function

def login(remote_conn, username, password):
        output = remote_conn.read_until("sername:", TELNET_TIMEOUT)
        remote_conn.write(username + '\n')
        # += indicates to keep the ouput
        output += remote_conn.read_until("ssword:", TELNET_TIMEOUT)
        remote_conn.write(password + '\n')
        return output

def telnet_connect(ip_addr):
        try:
                return telnetlib.Telnet(ip_addr, TELNET_PORT, TELNET_TIMEOUT)
        except socket.timeout:
                sys.exit("Connection timed-out")

def main():
        ip_addr = 'ip address'
        username = 'name'
        password = 'password'

        remote_conn = telnet_connect(ip_addr)
        output = login(remote_conn, username, password)
        print output

        time.sleep(1)
        output = remote_conn.read_very_eager()

        output = send_command(remote_conn, 'term len 0')
        output = send_command(remote_conn, 'sh run | sec snmp')
        output = send_command(remote_conn, 'sh ver')

        print output + '\n'

        remote_conn.close()

if __name__ == "__main__":
        main()

{'fraction_non_alphanumeric': 0.09466746554823248, 'fraction_numerical': 0.0035949670461354103, 'mean_word_length': 2.5913978494623655, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '587916', 'n_tokens_mistral': 502, 'n_tokens_neox': 493, 'n_words': 132}