Skip to content

Instantly share code, notes, and snippets.

@Licenser
Created March 24, 2011 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Licenser/51d43bff9d076d36f4f3 to your computer and use it in GitHub Desktop.
Save Licenser/51d43bff9d076d36f4f3 to your computer and use it in GitHub Desktop.
(defn- parse-interface [ifstr]
(let [[_ iface flags] (re-find #"^(.*): flags=\d+<([^>]+)> mtu \d+ index \d+" ifstr)
flags (re-seq #"[^,]+" flags)]
{"interface" iface
"flags" flags
"ip" (second (re-find #"inet ([^\s]+)" ifstr))
"netmask" (second (re-find #"netmask ([^\s]+)" ifstr))
"broadcast" (second (re-find #"broadcast ([^\s]+)" ifstr))
"ether" (second (re-find #"ether ([^\s]+)" ifstr))
"groupname" (second (re-find #"groupname ([^\s]+)" ifstr))}))
(register-command
"Interfaces"
"su \"root\" -c \"ifconfig -a\""
(fn [s]
(map
(fn [ifstr]
(parse-interface ifstr))
(re-seq #"(?m)^(?:[^\s].*)$(?:\n^[\s].*$)+" s))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment