Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. # KittensPaw - NETWORK MANAGEMENT AND MONITOR TOOL - BETA V.0.1 PYTHON IMPL
  2.  
  3. # KittensPaw - C++ RELEASE SHOULD BE USED WHEN POSSIBLE
  4.  
  5. import platform
  6. import subprocess
  7. import os
  8.  
  9.  
  10. # plan - multiple threads running loading into global variables that can be accessed
  11. # web thread - thread that manages web interface such as graphs, maps, etc
  12. # system thread - pings and retrieves and manages info from routers and other devices SNMP too
  13.  
  14.  
  15. # classes
  16.  
  17. class Router: # equipment class for routers and possible switches (note switches may get their own class)
  18. equipment_name = ""
  19. ip_address = ""
  20. # lat/long cords
  21. # parent maybe????
  22.  
  23. def __init__(self, equipment_name, ip_address):
  24. self.equipment_name = equipment_name
  25. self.ip_address = ip_address
  26.  
  27.  
  28.  
  29. # functions
  30.  
  31. def ping(host): # pings host
  32. """
  33. Returns True if host (str) responds to a ping request.
  34. Remember that a host may not respond to a ping (ICMP) request even if the host name is valid.
  35. """
  36.  
  37. # Option for the number of packets as a function of
  38. param = '-n' if platform.system().lower()=='windows' else '-c'
  39.  
  40. # Building the command. Ex: "ping -c 1 google.com"
  41.  
  42. command = ['ping', param, '1', host]
  43.  
  44. return subprocess.call(command) == 0
  45.  
  46.  
  47. # main
  48.  
  49. def main():
  50. print("Type router name...")
  51. name = input("Enter name: ")
  52. ip = input("Enter IP address: ")
  53.  
  54.  
  55. london = Router(name, ip)
  56. print ("Checking if " , london.equipment_name , " is online...")
  57. testing = ping(london.ip_address)
  58. if testing == True:
  59. print(london.equipment_name , " can ping!")
  60. else:
  61. print(london.equipment_name , " is offline!")
  62.  
  63.  
  64. if __name__== "__main__":
  65. main()
  66.  
  67.  
  68. # print("world hello!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement