Community discussions

MikroTik App
 
FranCruzarianick
just joined
Topic Author
Posts: 2
Joined: Tue Mar 01, 2022 11:47 am

loop in python not working for all line in text file

Thu Apr 21, 2022 1:34 pm

Hi
this code for get identity of mikrotik device. after run this code. only work for last IP

lines in ip.txt

192.168.3.6 --> NET_6
192.168.3.8 --> NET_8
192.168.3.10 --> NET_10
import os
filename = 'ip.txt'
with open(filename, 'r') as f:
for line in f:
pq = os.popen('plink -batch admin@' + line + ' -pw 123456@ "/system identity print"')
line = pq.readline()
print(line)
Using username "admin".
Using username "admin".

name: NET_10
 
User avatar
Buckeye
Forum Veteran
Forum Veteran
Posts: 893
Joined: Tue Sep 11, 2018 2:03 am
Location: Ohio, USA

Re: loop in python not working for all line in text file

Sat Apr 23, 2022 1:25 am

indentation is significant in python. specifically loops in your case.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: loop in python not working for all line in text file

Sat Apr 23, 2022 1:49 am

is indented, simply html do not show significant spaces (I do not check if is indented rightly)
new user do not know the use of [ code] blocks

python code

import os
filename = 'ip.txt'
with open(filename, 'r') as f:
    for line in f:
        pq = os.popen('plink -batch admin@' + line + ' -pw 123456@ "/system identity print"')
        line = pq.readline()
        print(line)

Who is online

Users browsing this forum: Dude2048, mkx, raiser and 38 guests