Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0

Writing a string to a file


i made a program to send a redstone signal when it receives a message from a wireless card and to ignore messages from cards that dont match the one in my tablet.

at the current moment though, it doesn't do anything to log unauthorized addresses, which is what i need help with.

i need to be able to place any wireless card address besides mine in a file called blacklist.txt; how do i do that? (also, if it's no bother; how would i make a whitelist to approve all addresses that are stored in a file?)

Share this post

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 1


I need some help to understand what exactly you're trying to do.

You have a tablet and you want to use that tablet to send a message to a computer which emits a Redstone signal when a message from that tablet is received. Right?

And you want to log all addresses of computers that SEND messages to the Redstone controlling computer? This is where I get lost. I mean, it it easy to log addresses of computers that send messages, but what information do you want to gain from this? All you will see is some random uuid which doesn't tell you anything.

And the last part I don't really get either. You want a file to blacklist addresses, right? Wouldn't it be MUCH simpler to whitelist all your devices that you want to be able to interact with this computer, since there are endless possibilities for addresses and you can't list them all.

Anyways, I'll show you 2 possibilities for whitelisting, if you still want to log the other addresses, I can show you how.

#1 Simply filter by address, if it's yours, it will do some stuff.

local event = require "event"

local e, rec_addr, send_addr, port, dist, msg = event.pull("modem_message")
if send_addr == "your address" then    --# fill in your tablet's address
  --# do stuff (i your case, redstone stuff)
  --# do other stuff or simply ignore messages from unknown computers
  --# here you can inplement logging of addresses


#2 using a whitelist

local event = require "event"

local path = "path/to/file"    --# enter the path you your file, for example "/etc/whitelist.txt"

local function load_whitelist()
  local file, reason = io.open(path, "r")
  if not file then
  local data = file:read("*all")

  local whitelist = {}
  for addr in data:gmatch('^(.-)\n$') do
    whitelist[addr] = true
  return whitelist

local whitelist = load_whitelist()

local e, rec_addr, send_addr, port, dist, msg = event.pull("modem_message")
if whitelist[send_addr] then
  --# do stuff
  --# do other stuff

 There a of cause tons of ways of how to structure the whitelist, I went with an easy one: each address is written in a new line, this way you can simply open the whitelist file with edit and delete an old address or enter a new one



Share this post

Link to post
Share on other sites
  • 0

sorry just saw this

there's no reason reason to log the addresses atm, i just thought it'd be neat. i think if i can log the time at which the address tried to send a message, though, i could definitely do something with that.


still, though, i think it would be pretty cool to have a blacklist of *ahem* "malicious" addresses.

Share this post

Link to post
Share on other sites
  • 0

As you seem to favor the whitelist approach, I would use CptMercury's 2nd option, and just log the address and message that we get from the modem message, and get the time from os.date().  something like

log_file.write(string.format("%s: Got '%s' from %s.\n", os.date(), msg, send_addr))

in the else clause.


You only need a whitelist or a blacklist, as everything not on one is assumed to be on the other. 

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.