Category Archives: Helpful

How to Get the MAC Address From a Local IP Address

Command

ping -c 1 192.168.1.1 > /dev/null && arp -a | grep 192.168.1.1

This returns something like this:

? (192.168.1.1) at 61:02:6a:40:34:A3 on en0 ifscope [ethernet]

How does this work?

The command pings the IP address once to make sure that your machine and the target machine communicated at least once. Because we don’t need the output of the ping command, we can simply pipe it into /dev/null. It then continues and loads all entries from ARP (Address Resolution Protocol) and “greps” the line which matches with the provided IP address.

Careful with IPv6!

ARP is IPv4 only. For IPv6 you need to use NDP (Neighbor Discovery Protocol). Simply replace “arp -a” with “ndp -a” above.

Mongoose: Cannot read property ‘paths’ of undefined

When working with Mongoose, make sure you never ever name a property “type”, since it’s reserved for declaring datatypes on fields. Take a look at this:

permissions: {
  type: String,   // this will throw an error
  userGroups: [
    {
      group: { type: mongoose.Schema.Types.ObjectId, ref: 'UserGroups' },   // correct use of "type"
      permission: String
    }
  ]
}

This will throw an uncaught exception. I’m writing this post so I can save you 20 minutes of debugging. Here’s the correct approach:

permissions: {
  permissionType: String,   // correct usage
  userGroups: [
    {
      group: { type: mongoose.Schema.Types.ObjectId, ref: 'UserGroups' },
      permission: String 
    }
  ]
}