-
-
Save Licenser/51d43bff9d076d36f4f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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