Advertisement
Guest User

Minecraft OC Server Pinger

a guest
Oct 28th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. local component = require("component")
  2. if not component.internet then
  3. io.stderr("No internet card avaliable")
  4. return
  5. end
  6. if not component.internet.isTcpEnabled() then
  7. io.stderr("Tcp is not enabled")
  8. return
  9. end
  10.  
  11. local process = require("process")
  12. local filesystem = require("filesystem")
  13. local internet = require("internet")
  14. local thisFolder = filesystem.path(process.running())
  15.  
  16. --local definitions = dofile(filesystem.concat(thisFolder, "definitions.lua"))
  17.  
  18.  
  19. local address = "ADDRESS OF SERVER" -- address of the server, change this
  20. local port = 25565 -- change if the server isn't on the default port
  21. local handle = internet.open(address,port)
  22.  
  23. --length
  24. handle:write(string.char(6 + address:len()))
  25. --packet id
  26. handle:write(string.char(0))
  27. --version
  28. handle:write(string.char(4))
  29. --address
  30. handle:write(string.char(address:len()))
  31. handle:write(address)
  32. --port
  33. handle:write(string.char(bit32.band(bit32.rshift(port,8),0xff)))
  34. handle:write(string.char(bit32.band(port,0xff)))
  35. --next state
  36. handle:write(string.char(1))
  37.  
  38. --request
  39. handle:write(string.char(1))
  40. handle:write(string.char(0))
  41.  
  42. handle:flush()
  43.  
  44. os.sleep(1)
  45.  
  46. local function readNum()
  47. local num = 0
  48. local lastRead
  49. local shift = 0
  50. repeat
  51. lastRead = handle:read(1):byte()
  52. num = num + bit32.lshift(bit32.band(lastRead, 0x7f),shift)
  53. shift = shift + 8
  54. until bit32.band(lastRead, 0x80) ~= 0x80
  55. return num
  56. end
  57.  
  58. --response
  59. local length = readNum()
  60. local id = handle:read(1):byte()
  61. local strLen = readNum()
  62. local response = handle:read(strLen)
  63.  
  64. print(response)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement