Restrict a R code to a certain local machine

Asked

Viewed 45 times

1

Does anyone know if it is possible to restrict the execution of a particular code created in R to a certain local machine? If so, what would be the code?

1 answer

3

The command Sys.info() returns system information, including the name of the machine on the network (nodename).

    Sys.info()
#                         sysname                      release 
#                       "Windows"                      "7 x64" 
#                         version                     nodename 
#    "build 7601, Service Pack 1"                "TBRDBZVRLZ1" 
#                         machine                        login 
#                        "x86-64"                     "tbrvlj" 
#                            user               effective_user 
#                        "tbrvlj"                     "tbrvlj" 

With this command you can identify the nodename and include a condition in its code:

nname <- Sys.info()['nodename']

if(nname == 'TBRDBZVRLZ1') {

  print("executa o código")

} else {

  print("não executa o código")

}
#    [1] "executa o código"
  • It is good to note that this solution is not safe. Just open the code and change the name of the machine to work again.

  • 1

    @Danielfalbel, what’s the safest alternative?

  • There is no secure solution if you have to pass the code . R to be executed by the client.. With a little knowledge he can always change the code and disable these protections. The secure solution is for you to stay in control of the server running the code - ex develop an API or app.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.