Posted 04 October 2015 - 12:39 AM
So I'm basically creating a table on modems and instead of being i1, i2, i3, etc. They are all overwriting each other:
Image:
--> Variables <--
local build = 110.00
interfaces = {}
local settings = {
[ "Threat Detection" ] = {
[ "enabled" ] = false, -- true / false
[ "pps" ] = 0, -- 0 - 20+
[ "onOver" ] = "none", -- shun / reject / none
[ "exclude" ] = {} -- excluded ip's from getting shunned
}
}
--> Functions <--
function logInfo(message)
term.setTextColor(colors.blue)
log(message)
end
function logWarn(message)
term.setTextColor(colors.yellow)
log(message)
end
function logErr(message)
term.setTextColor(colors.red)
log(message)
end
function log(message)
print(message)
end
function DecToBase(val,base)
if val == 0 then return 0 end
local b, k, result, d = base or 10, "0123456789ABCDEFGHIJKLMNOPQRSTUVW",""
while val > 0 do
val, d = math.floor(val/B)/>/>/>, math.fmod(val,B)/>/>/>+1
result = string.sub(k,d,d)..result
end
return result
end
function getMac(side)
local sidesTable = {top = 1,bottom = 2,left = 3,right = 4,back = 5,front = 6}
side = tostring(side)
local macBuffer = tostring(DecToBase(os.computerID() * 6 + sidesTable[side],6))
local MACaddr = string.rep("0",4-#macBuffer).. macBuffer
return MACaddr
end
function openModems()
local sides = rs.getSides()
for i=1, #sides do
if peripheral.getType(sides[i]) == "modem" then
interfaces[("i" .. #interfaces + 1)] = {
[ "MAC" ] = getMac(sides[i]),
[ "modem" ] = peripheral.wrap(sides[i]),
[ "RX" ] = {
[ "packets" ] = 0,
[ "errors" ] = 0,
[ "dropped" ] = 0,
[ "bytes" ] = 0,
},
[ "TX" ] = {
[ "packets" ] = 0,
[ "errors" ] = 0,
[ "dropped" ] = 0,
[ "bytes" ] = 0,
},
}
interfaces[("i" .. #interfaces + 1)].modem.open(1)
logInfo("Opened " .. "i" .. #interfaces + 1)
end
end
for k, v in pairs(interfaces) do
print(k .. " > " .. tostring(v))
end
end
--> Main Loop <--
logInfo("Begin POST")
openModems()
Image:
Edited on 03 October 2015 - 10:53 PM