Paste number 339464: select network interfaces based on regexp

Paste number 339464: select network interfaces based on regexp
Pasted by: Apteryx
When:3 years, 5 months ago
Share:Tweet this! | http://paste.lisp.org/+79XK
Channel:None
Paste contents:
Raw Source | XML | Display As
;;; Q: Is this a sane way to do what I want in Scheme?

 ;; When invoked without any interface argument, 'dhclient'
 ;; discovers all non-loopback interfaces *that are up*. However,
 ;; the relevant interfaces are typically down at this point. Thus
 ;; we perform our own interface discovery here.
 (define all-interfaces-minus-loopback
   (remove loopback-network-interface? (all-network-interface-names)))
 ;; Select the interfaces based on the interfaces field of the
 ;; configuration record.
 (define selected-interfaces
   (map (lambda (pat)
          (remove unspecified?
                  (map (lambda (iface)
                         (when (string-match pat iface) iface))
                       all-interfaces-minus-loop-loopback)))
        (dhcp-client-configuration-interfaces config)))


# Python equivalent of selected_interfaces
def selected_interfaces(interfaces, patterns):
  selected_ifaces = []
  for pat in patterns:
    for iface in interfaces:
      if re.search(pat, iface):
        selected_ifaces.append(iface)
  return selected_ifaces

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.