Advertisement
BlueZero

Ping

Feb 6th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. function ping()
  2. fails = 0
  3. print("Testing Internet Connection.")
  4. print("")
  5. oldx, oldy = term.getCursorPos()
  6. print("Connection Test 1")
  7. http.request("http://www.example-failure.com/")
  8.         if os.pullEvent() == "http_success" then
  9.                 local oldx, oldy = term.getCursorPos()
  10.                 term.setCursorPos(46,oldy-1)
  11.                 io.write("Passed")
  12.         else
  13.                 local oldx, oldy = term.getCursorPos()
  14.                 term.setCursorPos(46,oldy-1)
  15.                 io.write("Failed")
  16.                 fails = fails+1
  17.         end
  18. sleep(1)
  19. print("Connection Test 2")
  20. http.request("http://www.example-failure.com/")
  21.         if os.pullEvent() == "http_success" then
  22.                 local oldx, oldy = term.getCursorPos()
  23.                 term.setCursorPos(46,oldy-1)
  24.                 io.write("Passed")
  25.         else
  26.                 local oldx, oldy = term.getCursorPos()
  27.                 term.setCursorPos(46,oldy-1)
  28.                 io.write("Failed")
  29.                 fails = fails+1
  30.         end
  31. sleep(1)
  32. print("Connection Test 3")
  33. http.request("http://www.example-failure.com/")
  34.         if os.pullEvent() == "http_success" then
  35.                 local oldx, oldy = term.getCursorPos()
  36.                 term.setCursorPos(46,oldy-1)
  37.                 io.write("Passed")
  38.         else
  39.                 local oldx, oldy = term.getCursorPos()
  40.                 term.setCursorPos(46,oldy-1)
  41.                 io.write("Failed")
  42.                 fails = fails+1
  43.         end
  44. sleep(1)
  45.         if fails == 0 then
  46.                 print("")
  47.                 print("")
  48.                 print("Test Complete, no failures detected.")
  49.                 sleep(1.5)
  50.         elseif fails == 1 then
  51.                 print("")
  52.                 print("")
  53.                 print("1 connection failures detected. A Website Host might be down however connectivity is still there.")
  54.                 print("")
  55.                 print("Test Complete.")
  56.                 sleep(1.5)
  57.         elseif fails == 2 then
  58.                 print("")
  59.                 print("")
  60.                 print("2 connection failures detected. Possible limited web connectivity.")
  61.                 print("")
  62.                 print("Test Complete.")
  63.                 sleep(1.5)
  64.         elseif fails == 3 then
  65.                 print("")
  66.                 print("")
  67.                 print("Catastrophic connection failure detected. A firewall or improper internet settings may be the problem.")
  68.                 print("")
  69.                 print("Test Complete.")
  70.         pingResult = 3
  71.                 sleep(1.5)
  72.         end
  73. end
  74.  
  75. ping()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement