Python Forum
A lot of confusion and I can't seem to solve this issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A lot of confusion and I can't seem to solve this issue
#7
(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.
Reply


Messages In This Thread
RE: A lot of confusion and I can't seem to solve this issue - by snippsat - Jul-24-2022, 05:36 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020