# How can i ask and save the mac address in a String?

**URL:** <https://discourse.processing.org/t/how-can-i-ask-and-save-the-mac-address-in-a-string/2782>\
**Category:** Processing\
**Created:** [August 19, 2018, 11:29pm UTC](https://discourse.processing.org/t/how-can-i-ask-and-save-the-mac-address-in-a-string/2782 "2018-08-19T23:29:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andress](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Andress](https://discourse.processing.org/u/Andress)\
**Post date:** [August 19, 2018, 11:29pm UTC](https://discourse.processing.org/t/how-can-i-ask-and-save-the-mac-address-in-a-string/2782/1 "2018-08-19T23:29:09Z")

</div>

what library do i need ? what is the command ?. Thank you all !

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [August 20, 2018, 12:15am UTC](https://discourse.processing.org/t/how-can-i-ask-and-save-the-mac-address-in-a-string/2782/2 "2018-08-20T00:15:31Z")

</div>

No libraries needed. Just use `text()`.

```auto
boolean done = false;
String mac = "";

void setup(){
  size(400,400);
}

void draw(){
  background(0);
  fill(255);
  text("Please type in your MAC address.", 20, 20);
  text("Press enter when you are done.", 20, 40);
  fill(done?0:255,255,0);
  text(mac, 20, 60);
  if(done){
    fill(0,0,255);
    text("Thank you.", 20, 80);
  }
}

void keyPressed(){
  if( mac.length() > 0 && (keyCode == BACKSPACE || keyCode == DELETE) ){
    mac = mac.substring(0,mac.length()-1);
  }
  if( keyCode == ENTER || keyCode == RETURN ){
    done = true;
  }
  if( !done ){
    if( key >= 'a' && key <= 'f' ){
      mac = mac + char( key - 'a' + 'A' );
    }
    if( key >= 'A' && key <= 'F' ){
      mac = mac + char( key );
    }
    if( key >= '0' && key <= '9' ){
      mac = mac + char( key );
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [August 20, 2018, 12:36am UTC](https://discourse.processing.org/t/how-can-i-ask-and-save-the-mac-address-in-a-string/2782/3 "2018-08-20T00:36:52Z")

</div>

Okay, okay. That was mean of me. A little Google search turned up enough code to do it in Java mode. You’re probably out of luck in JavaScript modes though, for security reasons.

```auto
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;

void setup() {
  size(200,200);
  InetAddress ip;
  try {
    ip = InetAddress.getLocalHost();
    //println("Current IP address : " + ip.getHostAddress());
    NetworkInterface network = NetworkInterface.getByInetAddress(ip);
    byte[] mac = network.getHardwareAddress();
    print("Current MAC address : ");
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < mac.length; i++) {
      sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
    }
    System.out.println(sb.toString());
  } 
  catch (UnknownHostException e) {

    e.printStackTrace();
  } 
  catch (SocketException e) {

    e.printStackTrace();
  }
}

void draw() {
  background(0);
  exit();
}

```

YMMV

---

<div class="post-metadata">

**Author:** ![Andress](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Andress](https://discourse.processing.org/u/Andress)\
**Post date:** [August 20, 2018, 1:27am UTC](https://discourse.processing.org/t/how-can-i-ask-and-save-the-mac-address-in-a-string/2782/4 "2018-08-20T01:27:35Z")

</div>

I had already seen that code but I didn’t know I could type it in processing. Thank youuuu !
