#!/bin/bash
gendnsmasqvars() {
#--dhcp-fqdn
  dnsmasq_dhcp=dhcp-authoritative
  dnsmasq_domain=
  while read iface st ips; do
      iface=${iface%@*}
      for ip in $ips; do
  #        echo $iface $ip ${ip%/*} ${ip%.*} $(getent hosts ${ip%/*})
          np=${ip%.*}
          domain=$(getent hosts ${ip%/*})
          if [ ! -z "$domain" ]; then
              domain=${domain#* *.}
              printf -v dnsmasq_domain "domain=$domain,$np.0/24,local"
          fi
          printf -v dnsmasq_dhcp "%s\ndhcp-range=%s.10,%s.200,255.255.255.0,1h" \
          "$dnsmasq_dhcp" "$np" "$np"
      done
  done < <(ip -4 -br a | grep ^lan)
}
