Jul-24-2022, 05:36 PM
(Jul-24-2022, 04:55 PM)Calli Wrote: This is working fine but how do you loop through all the ip which is in a file?When you do this it will just be one big string object,that you can not iterate over.
Have to spilt it up for this to work.
ip_list = file_read.read()Let say this is content.
ip_lst1.txt
Output:118.31.106.59
118.31.106.59
118.31.106.59
Can just iterated over file object,no need to read()(and split it up).import requests with open('ip_lst1.txt') as f: for ip in f: ip = ip.strip() print(ip) response = requests.get(f"http://{ip}:9200/_cat/indices") print(response.text.strip())
Output:118.31.106.59
green open .geoip_databases vtWge-U1SLefV6CuavYxCQ 1 0 40 40 37.7mb 37.7mb
118.31.106.59
green open .geoip_databases vtWge-U1SLefV6CuavYxCQ 1 0 40 40 37.7mb 37.7mb
118.31.106.59
green open .geoip_databases vtWge-U1SLefV6CuavYxCQ 1 0 40 40 37.7mb 37.7mb
Doing most task will be will be a struggle if you don't spend time learning📜 basic Python.