This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
HydroNitrogen's profile picture

RedNet sniffer program - problems

Started by HydroNitrogen, 12 June 2015 - 06:29 PM
HydroNitrogen #1
Posted 12 June 2015 - 08:29 PM
Hey guys!
Im creating a rednet sniffer program that will log all received rednet messages.

here is a part of the code:

while controlLoop == true do
  local senderId, message, protocol = rednet.receive(1)
  local time = os.time()
  local day = os.day()
  local eventtime = textutils.formatTime(time, true)
  if message ~= "" then
    local snifftime = eventtime
    term.setCursorPos(1,5)
    term.setBackgroundColor(colors.lightGray)
    term.setTextColor(colors.black)
    term.clearLine()
    term.write("Most recent sniffed data:")
    term.setBackgroundColor(colors.gray)
    term.setTextColor(colors.black)
    term.setCursorPos(1,6)
    term.clearLine()
    term.setCursorPos(1,7)
    term.clearLine()
    term.write("Time:        "..tostring(snifftime))
    term.setCursorPos(1,8)
    term.clearLine()
    term.write("Sender ID:   "..tostring(senderId))
    term.setCursorPos(1,9)
    term.clearLine()
    term.write("Protocol:    "..tostring(protocol))
    term.setCursorPos(1,10)
    term.clearLine()
    term.write("Payload:     "..tostring(message))
  end

  -- render
  term.setBackgroundColor(colors.black)
  term.setTextColor(colors.white)
  term.clear()

  term.setCursorPos(1,h)
  term.setBackgroundColor(colors.white)
  term.setTextColor(colors.black)
  term.clearLine()
  term.write("Time: "..eventtime.." - Day: "..day)
end

Now you see that, it perfectly updates the time every second.
But it doesnt show any rednet messages.

Its a bit messy, but I hope you could see my problem.

Thanks and have a nice day :)/>
biggest yikes #2
Posted 12 June 2015 - 08:42 PM
rednet.receive() is a rednet function, of course it isn't going to sniff rednet messages.
All rednet messages are sent on channel 65533 aswell, however, so using the modem API you'll have to listen to that channel and wait for "modem_message" events.
HydroNitrogen #3
Posted 12 June 2015 - 08:51 PM
Oh wait, I misread the wiki, I will change to the modem API with the channel 65533.

So there I will be able to sniff all rednet messages?
valithor #4
Posted 12 June 2015 - 09:04 PM
rednet.receive() is a rednet function, of course it isn't going to sniff rednet messages.
All rednet messages are sent on channel 65533 aswell, however, so using the modem API you'll have to listen to that channel and wait for "modem_message" events.

65533 is actually the channel the gps program uses
65535 is the rednet broadcast channel

Any message sent with rednet.send is sent on the channel specified, and rednet.open opens the channel that corresponds with the id of the computer and also opens 65535.

So no not all rednet messages are sent on a single channel.

Either way he will want to use the modem api instead of the rednet api.
Edited on 12 June 2015 - 07:05 PM
biggest yikes #5
Posted 12 June 2015 - 09:05 PM
Oh wait, I misread the wiki, I will change to the modem API with the channel 65533.

So there I will be able to sniff all rednet messages?
Yes.
However, this doesn't mean you can sniff all messages, if the user sending the message uses the modem API this method won't function.
The message sent back is a table, with the person it aimed at being "nRecipient" and the actual string message being "message".
rednet.receive() is a rednet function, of course it isn't going to sniff rednet messages.
All rednet messages are sent on channel 65533 aswell, however, so using the modem API you'll have to listen to that channel and wait for "modem_message" events.

65533 is actually the channel the gps program uses
65535 is the rednet broadcast channel

Any message sent with rednet.send is sent on the channel specified, and rednet.open opens the channel that corresponds with the id of the computer and 65535.

Either way he will want to use the modem api instead of the rednet api.
Wrong, 65535 is the repeater channel (rednet.broadcast). The GPS one is 65534 (although if you're using this channel you should use gps.CHANNEL_GPS).
He's looking for the channel that rednet.send messages are sent to, not just rednet.broadcast.
Edited on 12 June 2015 - 07:12 PM
valithor #6
Posted 12 June 2015 - 09:09 PM
Oh wait, I misread the wiki, I will change to the modem API with the channel 65533.

So there I will be able to sniff all rednet messages?
Yes.
However, this doesn't mean you can sniff all messages, if the user sending the message uses the modem API this method won't function.
The message sent back is a table, with the person it aimed at being "nRecipient" and the actual string message being "message".
rednet.receive() is a rednet function, of course it isn't going to sniff rednet messages.
All rednet messages are sent on channel 65533 aswell, however, so using the modem API you'll have to listen to that channel and wait for "modem_message" events.

65533 is actually the channel the gps program uses
65535 is the rednet broadcast channel

Any message sent with rednet.send is sent on the channel specified, and rednet.open opens the channel that corresponds with the id of the computer and 65535.

Either way he will want to use the modem api instead of the rednet api.
Wrong, 65535 is the repeater channel (rednet.broadcast). The GPS one is 65534 (although if you're using this channel you should use gps.CHANNEL_GPS).

I wasnt sure so I checked in game… but apparently we were both wrong lol

65535 = rednet.broadcast
65534 = gps
65533 = repeat

Either way it is pointless to listen only to the broadcasted messages, seeing as half of the rednet messages are not sent on that channel.
biggest yikes #7
Posted 12 June 2015 - 09:13 PM
65535 = rednet.broadcast
65534 = gps
65533 = repeat
But that's what I said?
I said 65535 is broadcast, 65533 is rednet.send messages.
Edited on 12 June 2015 - 07:14 PM
valithor #8
Posted 12 June 2015 - 09:19 PM
65535 = rednet.broadcast
65534 = gps
65533 = repeat
But that's what I said?
I said 65535 is broadcast, 65533 is rednet.send messages.

65533 is in no way related to rednet.send. It is the channel the relay program uses. Rednet.send messages are sent on the channel that is returned by os.getComputerID. However, lets try and actually answer his question lol.

From what I understand he is trying to record any messages that computer receives. Since he did not say he wants to retrieve all of the rednet messages I will just assume he only wants the ones sent to that one computer.

From a quick glance at the code I do not see anything wrong other than the fact he never actually calls rednet.open, which prevents him from ever actually receiving any messages.

edit:

To actually monitor all rednet messages it would require 103 computers with 512 modems, with each modem having the maximum of 128 channels open and all channels open being different.

Don't trust my math?
The above is assuming you connect all of the computers via wired modem and cable in order to be able to easily transfer any information received.

Number of channels: 65535
Number of max channels per modem: 128
Max Number of wireless modems per comp with a wired modem on one side: 5

65535/(128*5) = number of comps
65535/128 = number of modems
Edited on 12 June 2015 - 07:47 PM
Bomb Bloke #9
Posted 13 June 2015 - 03:05 AM
65533 is in no way related to rednet.send. It is the channel the relay program uses. Rednet.send messages are sent on the channel that is returned by os.getComputerID. However, lets try and actually answer his question lol.

To be clear on this, as of CC 1.6, rednet.send() transmits on whatever channel you request, and a slightly modified version on channel 65533 which can be converted back to match the original message. rednet.broadcast() calls rednet.send() and requests it transmit on channel 65535, so both that and 65533 end up being used.

The reason for this is so that the repeat script doesn't have to listen on every single available channel in order to function. It listens on channel 65533, and sees all rednet traffic.

Likewise, if you want to write a script that monitors all rednet messages in the area, you only need to listen on that one channel. From there, you can see the message contents, where they came from, and who the intended recipients are. The source of the repeat script and of the rednet API demonstrates the details.

Of course, if you want to capture non-rednet messages, it's an entirely different kettle of fish.
HydroNitrogen #10
Posted 13 June 2015 - 12:27 PM
Thanks for all the reactions :)/>

So to be clear… I need to use the modem API to listen to channel 65535, and then I will receive all Rednet broadcast and send traffic that is in range of my modem?
valithor #11
Posted 13 June 2015 - 12:41 PM
Thanks for all the reactions :)/>/>

So to be clear… I need to use the modem API to listen to channel 65535, and then I will receive all Rednet broadcast and send traffic that is in range of my modem?

It appears my information was dated. From what bomb bloke said, you will want to listen to 65533.

I wasn't aware the API had changed since I had learned it.
biggest yikes #12
Posted 13 June 2015 - 03:50 PM
you should know the response is a table. "nRecipient" in that table is the ID it was supposed to be sent to, and "message" is the actual string message.
If it's not a table, you should just ignore the message, as otherwise it might just be a message sent via the modem API to ID 65533.
Edited on 13 June 2015 - 01:51 PM