Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --DNS
- term_x, term_y = term.getSize()
- id = os.computerID()
- version = "v 1.0"
- modemSide = ""
- sides = {"top", "bottom", "left", "right", "front", "back"}
- privateKey = 30679223
- modN = 43888321
- PackageIdentifier = "_GOO.pack"
- pack_pos = 1;
- function findModem()
- for i = 1, #sides, 1 do
- if (peripheral.getType(sides[i]) == "modem") then
- modemSide = sides[i]
- end
- end
- if (modemSide == "") then return false end
- return true
- end
- function readBytesFromPack(d, b)
- s = string.sub(d, pack_pos, pack_pos + b)
- pack_pos = pack_pos +b +1
- return s
- end
- function isValidPackage(s)
- head = readBytesFromPack(s, string.len(PackageIdentifier))
- if (head == PackageIdentifier) then
- return true
- end
- return false
- end
- function resolveAddr(a)
- f = fs.open("servers.ls", "r")
- for line in file:lines() do
- s,e = string.find (line, a)
- if (s ~= nil) then
- return string.sub(line, e+1)
- end
- end
- end
- function parsePackage(data, sId, dis)
- packId = toNumber(readBytesFromPack(data, 3))
- if (packId == 01) then --DNS REQ
- l = toNumber(readBytesFromPack(data, 2))
- addr = readBytesFromPack(data, l)
- res = resolveAddr(addr)
- print(res)
- end
- end
- ------------------------------------
- term.clear()
- term.setCursorPos(1,1)
- print("Google DNS id: "..id)
- if (findModem() == false) then print("No modem found!") os.shutdown() end
- print("Found modem at side: "..modemSide);
- rednet.open(modemSide)
- print("Rednet opened")
- print("operating...")
- while true do
- _event, _senderId, _data, _distance = os.pullEvent("rednet_message")
- pack_pos = 1;
- if (isValidPackage(_data)) then
- parsePackage(_data, _senderId, _distance)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment