Advertisement
Sanwiches

netMon

Jan 10th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. local function getDevices(deviceType) -- This function was taken from https://github.com/sandalle/minecraft_bigreactor_control and has been modified by https://github.com/Sanwi
  2. local deviceName = nil
  3. local deviceIndex = 1
  4. local deviceList, deviceNames = {}, {} -- Empty array, which grows as we need
  5. local peripheralList = peripheral.getNames() -- Get table of connected peripherals
  6. for peripheralIndex = 1, #peripheralList do -- Log every device found
  7. if (string.lower(peripheral.getType(peripheralList[peripheralIndex])) == deviceType) then -- Log devices found which match deviceType and which device index we give them
  8. deviceNames[deviceIndex] = peripheralList[peripheralIndex]
  9. deviceList[deviceIndex] = peripheral.wrap(peripheralList[peripheralIndex])
  10. deviceIndex = deviceIndex + 1
  11. end
  12. end -- for peripheralIndex = 1, #peripheralList do
  13. return deviceList, deviceNames
  14. end
  15.  
  16. local function listen(modem,channels)
  17. --Open channels
  18. for i=1, #channels do
  19. modem.setListening(channels[i],true)
  20. end
  21.  
  22. --Listen
  23. local event, modemSide, senderID, channel, message = os.pullEvent("lan_message")
  24.  
  25. --Close channels
  26. for i=1, #channels do
  27. modem.setListening(channels[i],false)
  28. end
  29. local channel = tonumber(channel)
  30. return event, modemSide, senderID, channel, message
  31. end
  32.  
  33. channels = {101,102,103,104}
  34. deviceList, deviceNames = getDevices("lan nic")
  35. modem = deviceList[1]
  36. modem.setPromiscuous(true)
  37. while true do
  38. local event, modemSide, senderID, channel, message = listen(modem,channels)
  39. print(senderID..":"..message)
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement