Python Forum
Loop through list of ip-addresses [SOLVED]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loop through list of ip-addresses [SOLVED]
#1
Hello everybody,

I want to use a python script to check if certain ips are still online and if not, i want the system to shut down.
Therefore I have created a list of client ip's and a loop to check every ip if its online or not and then, if all ip's are down, execute a command (in this example it is the command #Command1) and if not, it should execute another command (in this exampe #Command2).

def ip_check():
    hosts = [
    "192.168.180.100",
    "192.168.180.101",
    "192.168.180.102",
    "192.168.180.103",
    "192.168.180.104",
    "192.168.180.105",
    "192.168.180.106"
    ]
   
    for x in hosts:
        host_response = os.system("ping -c 1 " + str(hosts))

    if guest_response == 0:
        #Command1
    else:
        #Command2
The problem is, all i get is this output and I don't know how to fix it:
ping: 192.168.180.106]: Name or service not known
ping: 192.168.180.106]: Name or service not known
ping: 192.168.180.106]: Name or service not known
ping: 192.168.180.106]: Name or service not known
ping: 192.168.180.106]: Name or service not known
ping: 192.168.180.106]: Name or service not known
ping: 192.168.180.106]: Name or service not known
Reply


Messages In This Thread
Loop through list of ip-addresses [SOLVED] - by AlphaInc - May-11-2022, 01:31 PM
RE: Loop through list of ip-addresses - by AlphaInc - May-11-2022, 01:52 PM
RE: Loop through list of ip-addresses - by AlphaInc - May-11-2022, 02:06 PM
RE: Loop through list of ip-addresses - by AlphaInc - May-11-2022, 02:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] Loop through directories and files one level down? Winfried 3 505 Apr-28-2024, 02:31 PM
Last Post: Gribouillis
  [solved] list content check paul18fr 6 965 Jan-04-2024, 11:32 AM
Last Post: deanhystad
  [SOLVED] [loop] Exclude ranges in… range? Winfried 2 1,759 May-14-2023, 04:29 PM
Last Post: Winfried
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,484 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Response.json list indices must be integers or slices, not str [SOLVED] AlphaInc 4 6,915 Mar-24-2023, 08:34 AM
Last Post: fullytotal
  [SOLVED] [Linux] Script in cron stops after first run in loop Winfried 2 1,065 Nov-16-2022, 07:58 PM
Last Post: Winfried
  [SOLVED] [BS] Why new tag only added at the end when defined outside the loop? Winfried 1 1,067 Sep-05-2022, 09:36 AM
Last Post: snippsat
  a function to get IP addresses of interfaces Skaperen 2 1,578 May-30-2022, 05:00 PM
Last Post: Skaperen
  [solved] Basic question on list matchiing paul18fr 7 2,094 May-02-2022, 01:03 PM
Last Post: DeaD_EyE
  [solved] Sort list paul18fr 5 3,064 Aug-18-2021, 06:34 AM
Last Post: naughtyCat

Forum Jump:

User Panel Messages

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