Skip to content

Instantly share code, notes, and snippets.

@paralax
Last active August 29, 2015 14:23
Show Gist options
  • Save paralax/ebec2ae733b658c4f8da to your computer and use it in GitHub Desktop.
Save paralax/ebec2ae733b658c4f8da to your computer and use it in GitHub Desktop.
scala to get arp mappings
import scala.sys.process._
val IP_PAT="(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})".r
val MAC_PAT="([a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2}:[a-f0-9]{1,2})".r
val res = "arp -na" !!
(IP_PAT + "[^\\d]* .+ " + MAC_PAT).r.findAllMatchIn(res).map(_.subgroups).map(x => (x.head, x.last)).toMap // cala.collection.immutable.Map[String,String] = Map(192.168.0.102 -> 80:e6:50:25:xx:xx, ...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment