Jump to content




ANOTHER problem with my internet system


3 replies to this topic

Poll: ANOTHER problem with my internet system

Should I release this internet system when I'm done with it?

You cannot see the results of the poll until you have voted. Please login and cast your vote to see the results of this poll.

If you think I should release it, how should I name it?

You cannot see the results of the poll until you have voted. Please login and cast your vote to see the results of this poll.
Vote Guests cannot vote

#1 Windows10User

  • Members
  • 62 posts
  • LocationC:\Minecraft\saves\stuff\computer

Posted 10 May 2018 - 05:58 PM

I finally got my DNS and browser to work as they should. However, when the browser sends a request to the web server (to fetch the page), it doesn't work. The server receives the request for the page (the domain name + the name of the page) but doesn't seem to react to it and I know that because the browser won't stop waiting for the request!

Browser:
local modem = peripheral.find("modem")

if modem == nil then
   error("No modem found!", 0)
end

if not modem.isWireless() then
   error("Modem isn't wireless!")
end

print("Type the DNS ID:")
local dnschannel = tonumber(read())
print("Type the domain name:")
local domain = read()
print("Sending request. Press any key to cancel.")

modem.open(dnschannel)
modem.transmit(dnschannel, os.getComputerID(), string.match(domain, "[^/]+"))

local event, mSide, sChannel, rChannel, msg, dist = os.pullEvent("modem_message")
if msg == "FAIL" then
   error("DNS error.", 0)
else
   print(domain)
   modem.transmit(tonumber(msg), os.getComputerID(), domain)
   local event, mSide, sChannel, rChannel, msg, dist = os.pullEvent("modem_message")
   shell.run("clear")
   print("Contents:")
   print(msg)
end

Web server:
local domain = "something.com"

local modem = peripheral.find("modem")

if modem == nil then
	error("No modem found!", 0)
end

if not modem.isWireless() then
   error("Modem isn't wireless!")
end

modem.open(os.getComputerID())

while true do
   local event, mSide, sChannel, rChannel, msg, dist = os.pullEvent("modem_message")
   if fs.exists(string.sub(msg, string.len(domain) + 2)) then
	  print(string.sub(msg, string.len(domain) + 2))
	  local fPage = fs.open(string.sub(msg, string.len(domain) + 2), "r")
	  local page = fPage.readAll()
	  fPage.close()
	  modem.transmit(rChannel, os.getComputerID(), page)
   else
	  modem.transmit(rChannel, os.getComputerID(), "404 - Page Not Found")
   end
end

P. S. automatic code indentation WHEN

Edited by Windows10User, 10 May 2018 - 05:59 PM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 11 May 2018 - 05:13 AM

Here you're intending to have each computer send to a channel equal to the other's ID, and request that replies be sent back on a channel equal to their own ID.

But in your "browser" script, you have this:

modem.open(dnschannel)

The server doesn't send back to that channel, hence why the browser never sees a response from it. You're wanting both systems to call modem.open() with os.getComputerID() as the parameter.

Note that you don't have to use the computer ID numbers for your transmissions - that's a convention used by the rednet API (which is a wrapper for the modem's API you're using here), but there's nothing stopping you from just picking some random number like 23,456 and then hard-coding your systems to communicate on that channel. It'd save you from needing to enter your "dnschannel" all the time.

#3 Windows10User

  • Members
  • 62 posts
  • LocationC:\Minecraft\saves\stuff\computer

Posted 11 May 2018 - 05:17 AM

View PostBomb Bloke, on 11 May 2018 - 05:13 AM, said:

Note that you don't have to use the computer ID numbers for your transmissions - that's a convention used by the rednet API (which is a wrapper for the modem's API you're using here), but there's nothing stopping you from just picking some random number like 23,456 and then hard-coding your systems to communicate on that channel. It'd save you from needing to enter your "dnschannel" all the time.

I know, I can use 65535 if I wanted, but I'm using IDs for security sake, if you understand. :) And to prevent conflicts between the 3 systems.

Edited by Windows10User, 11 May 2018 - 05:18 AM.


#4 Marc1miner

  • Members
  • 8 posts

Posted 13 May 2018 - 07:53 AM

View PostWindows10User, on 11 May 2018 - 05:17 AM, said:

View PostBomb Bloke, on 11 May 2018 - 05:13 AM, said:

Note that you don't have to use the computer ID numbers for your transmissions - that's a convention used by the rednet API (which is a wrapper for the modem's API you're using here), but there's nothing stopping you from just picking some random number like 23,456 and then hard-coding your systems to communicate on that channel. It'd save you from needing to enter your "dnschannel" all the time.

I know, I can use 65535 if I wanted, but I'm using IDs for security sake, if you understand. :) And to prevent conflicts between the 3 systems.

If you want to secure at all time you should look at Diffie-Hellman key exchange, https://en.wikipedia...an_key_exchange
It basically does the folowing:
Both the browser and the website generate a random number
They send their public key over rednet for example.
With their public key they make one private key, and that could be any number form 0 - 65535
and that would be your protocol
It is extremely safe because you generate a new key every time, so it is very hard to guess for someone else to guess what protocol you're using.

How can you implement this?
function keyEchange(g, p)
local g = g -- g is the base, the server and browser have the same
local p = p -- p is the modulo, the server and browser have the same
local a = math.randomseed(os.time())
a = math.random(1,100)
local key = (g^a) % p    -- the server does the same calculation
rednet.open("top")
rednet.send(1, key)
local id, pKey = rednet.receive() -- pKey is the received public key
rednet.close("top")
local sKey = (pKey^a) % p -- sKey is the secret key
return sKey
end


Hopefully you find this useful!

By the way, is there anyway I can contact you more quickly as more as a coop?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users