From Mark CLohesy, 2 Months ago, written in Plain Text.
This paste will go to meet its maker in 8 Months.
Embed
  1. #!/usr/bin/python
  2. # This pings devices on LAN and WAN and displays UP/DOWN status on arduino LCD screen
  3. # The Messages for the LCD are hard coded in to the Arduino code so we only have to
  4. # send an ASCII code for each state message
  5. ####################################################################################################
  6.  
  7. import os
  8. import serial
  9. import time
  10.  
  11. # Functions ########################################################################################
  12.  
  13. # Ping Device for State and send state to arduino
  14. # Hostname = IP or name of device on network, up/down = ASCII code sent to arduino for up/down State
  15. def pingDev (hostname, up, down):
  16.         response = os.system("ping -c 1 -W 2 " + hostname)
  17.         if response == 0:
  18.                 byteSer = up
  19.         else:
  20.                 byteSer = down
  21.         time.sleep(1)
  22.         ser.write(chr(byteSer))
  23.         time.sleep(4)
  24.  
  25. # Initial Commands before main loop ################################################################
  26.  
  27. # Send Null to wake up arduino serial
  28. ser = serial.Serial('/dev/ttyUSB0', 9600)
  29. ser.write(chr(0))
  30. time.sleep(2)
  31.  
  32. #Main Loop #########################################################################################
  33.  
  34. while True:
  35.         pingDev( hostname="192.168.0.7", up=79, down=80 ); #DOROTHY (SHACK SWITCH)
  36.         pingDev( hostname="192.168.0.2", up=73, down=74 ); #OCTOPUS (MAIN SWITCH)
  37.         pingDev( hostname="192.168.0.1", up=69, down=70 ); #GARGOYLE (MODEM/ROUTER)
  38.         pingDev( hostname="110.232.242.101", up=83, down=84 ); #LOCAL WAN ADDRESS (FROM ISP)
  39.         pingDev( hostname="203.22.132.1", up=65, down=66 ); #DCSI (ISP)
  40.         pingDev( hostname="google.com", up=77, down=78 ); #GOOGLE (DNS CHECK)
  41.         pingDev( hostname="192.168.0.3", up=67, down=68 ); #SS-TITANIC (SERVER)
  42.         pingDev( hostname="192.168.0.5", up=71, down=72 ); #PHAZER (PRINTER)
  43.         pingDev( hostname="192.168.10.8", up=81, down=82 ); #FT-707 Rig PC (HIDDENPAD)
  44.         pingDev( hostname="192.168.30.2", up=75, down=76 ); #MYRRDIN (BRODIE WIRELESS DESKTOP)
  45.         pingDev( hostname="192.168.0.4", up=85, down=86 ); #LG PVR (LOUNGEROOM)
  46.         pingDev( hostname="192.168.20.1", up=87, down=88 ); #ISIS (JO-ANNES PC)
  47.         pingDev( hostname="192.168.40.1", up=89, down=90 ); #EXCALIBUR (ANGUS' PC)
  48.  
  49. ####################################################################################################
  50.  
  51.  
  52. # EOF