Python Forum
Need to build a ping test for work network
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need to build a ping test for work network
#1
This is my firs time posting and i am going to be as thorough as possible

my boss has requested that i make a python program on a raspberry pi (running raspbian), the parameters he requested are these:

the program should ping various network devices every 5 minutes
if the ping succeeds, send a signal to one of the GPIO pins
if the ping fails, send a signal to one of the GPIO pins

that signal will be sent to another device which will initiate an alarm.

I have come up with something based on internet searches, but i keep running into road blocks, and have a lot of questions...

here is the code i have:

=========================================
import ipaddress
import socket
import os


with open('test_list.txt') as fname:
           sw = fname.read().splitlines()
for s in sw:
    response = os.system('ping -n 2' + s)
    if response == 0:
               print(s, 'is up!')
    else:
               print(s, 'is Down!')
========================================


right now, i am getting this error, "if response= == 0 name "response" is not defined."

is it smart to run this based on a .txt file? i thought it would be good in case we want to add or remove IPs.

i am also wondering how to then take that output of the ping and make it trigger a high or low signal on the pin.

Sorry if this post broke all the rules... thanks in advance
Reply


Messages In This Thread
Need to build a ping test for work network - by austina2 - Mar-06-2019, 04:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ping program in python Skaperen 2 3,391 Jun-23-2018, 03:32 PM
Last Post: Skaperen
  TCP ping time mesure diffrence from other tools tbaror 2 3,423 Dec-25-2017, 08:57 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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