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

Get Network ID

Started by Hydrotronics, 20 August 2016 - 01:12 PM
Hydrotronics #1
Posted 20 August 2016 - 03:12 PM
Is it possible to get the network ID of the computer the program is running on? Not like os.computerID but like when you right click a wired modem. How would you get that ID? If you still don't know what I'm talking about, it's that ID that pops up in chat when right clicking wired modems like "computer_2" or "drive_324".
Lupus590 #2
Posted 20 August 2016 - 03:28 PM
If peripheral.getNames can't then I don't know what could.
Hydrotronics #3
Posted 20 August 2016 - 04:17 PM
perpheral.getNames would supply the id, but it would be pretty difficult to determine which one is you
KingofGamesYami #4
Posted 20 August 2016 - 04:46 PM
peripheral.getNames would not supply the id of a modem connected directly to the computer running the command. It would instead return the side of the connection (ei "right").

I'm not sure there is any way to know this, but I also do not know of any situation where this information is required. Perhaps you could elaborate on what you want to accomplish.
Hydrotronics #5
Posted 20 August 2016 - 04:48 PM
I wish to make an api which has this functionality in it. It could be useful for networking such as remote access. If you had the ID but not the network ID, you could send a message over to the computer and then tell it to do something along the lines of "monitor [computername] [program]…"

It doesn't have too many uses, but it has a couple. Also it's just fun :)/>
CoderPuppy #6
Posted 20 August 2016 - 07:50 PM
It is possible to find all the peripheral names that a computer has using `peripheral.getNames` (entirely untested):

local names = {}
for _, name in ipairs(peripheral.getNames()) do
  if peripheral.getType(name) == 'computer' and peripheral.call(name, 'getID') == os.getComputerID() then
    names[#names + 1] = name
  end
end

though looking at what you're doing you might rather want to get the id from a name which you can do like this (also entirely untested):

local id = peripheral.call(name, 'getID')
Lyqyd #7
Posted 20 August 2016 - 08:03 PM
Like KingofGamesYami mentioned, the above code will not work. Computers cannot find their network peripheral name on their own, it does not appear in the list returned by peripheral.getNames. The only possible way would be to enlist the assistance of another computer on the same network, by having it check the value returned by getID for other computers on the network, and report back to the first if its network name is found that way.
Lupus590 #8
Posted 20 August 2016 - 09:06 PM
It could be useful for networking such as remote access.

In which case you would use rednet, which uses the computer ID. You may want to have a look at nsh
Hydrotronics #9
Posted 06 September 2016 - 04:44 PM
It could be useful for networking such as remote access.

In which case you would use rednet, which uses the computer ID. You may want to have a look at nsh

I would use something like term.redirect() to show the screen, and then use rednet to send events. Though tbh your methods are probably better :D/>