0

I am new to R. I want to know how to extract MAC id of a system in R. Is there anything similar to uuid.getnode() in Python?

Arthur
  • 508
  • 2
  • 14
  • Use `system` or `system2` to call `ifconfig`, `ip`, or `ipconfig`, depending on whatever system you have. From there, just parse the output. – r2evans Jul 12 '19 at 05:48

1 Answers1

3

An idea would be to run system commands from R by using system and storing the result in a file which is explained in this answer.

On Linux

To get the MAC address in command line on Linux you would use (not tested on MAC) from here

$ ifconfig -a | grep -Po 'HWaddr \K.*$'

So the overall line in R would be :

mac_addr<- system("ifconfig -a | grep -Po 'HWaddr \K.*$'", intern = TRUE)

On Windows

mac_addr<- system("getmac", intern = TRUE)

Then parse the result as proposed by @r2evans

Arthur
  • 508
  • 2
  • 14
  • Without the error we can not help you further.. (please do not disclose your real MAC address, IP...) – Arthur Jul 15 '19 at 06:45
  • Error: '\K' is an unrecognized escape in character string starting ""ifconfig -a | grep -Po 'HWaddr \K" This is what it said when i tried mac_addr<- system("ifconfig -a | grep -Po 'HWaddr \K.*$'", intern = TRUE) – arpita welling Jul 15 '19 at 12:19
  • I don't have a Mac so I don't know, try `mac_addr<- system("ifconfig -a", intern = TRUE). You should have a string containing the mac address. Is it the case ? – Arthur Jul 15 '19 at 16:06
  • On which Operating System are you ? `getmac` is a Windows command – Arthur Jul 16 '19 at 06:42
  • I am on Windows. Trying to get MAC id of laptop in R. – arpita welling Jul 16 '19 at 08:49
  • So the macos tag in your post has nothing to do here. Then replace the Linux command in quotes by `"getmac"` and take a look at the string given as an output. – Arthur Jul 16 '19 at 08:55