Network Macros
The macros in the sample network_macros.cfg configuration file below deal with network matters such as host-address conversions, subnets, DNS, etc.
/////////////////////////////////////////////////////////////////////////////// // networking macros /////////////////////////////////////////////////////////////////////////////// addr2host(A) // for the given ipaddr (A), return the associated host (as // resolved by nslookup) // (A) is the ipaddr (e.g., 123.111.222.111) $trim($command("=nslookup -sil (A) 2>/dev/null | =egrep -i '^name:' | =awk '{print \$NF}'")) /////////////////////////////////////////////////////////////////////////////// nsname(H) // for host (H), return the Name: field from nslookup $trim($command("=nslookup -sil (H) 2>/dev/null | =egrep -i '^name:' | =awk '{print \$NF}'")) nsaddr(H) // for host (H), return the Address: field from nslookup $trim($command("=nslookup -sil (H) 2>/dev/null | =tail -n +4 | =egrep -i '^address:' | =awk '{print \$NF}'")) /////////////////////////////////////////////////////////////////////////////// fqdn(H) // for host (H), return the FQDN (fully qualified domain name); // if =nsname() (nslookup) results are nil, return (H) $if(#length(=nsname((H))), =nsname((H)), "(H)") /////////////////////////////////////////////////////////////////////////////// host2addr(H) // for the given host (H), return the associated addr (as // resolved by nslookup) // (H) is the host (e.g., hamburg.uppity.edu) $trim($command("=nslookup -sil (H) 2>/dev/null | =grep '^Address:' | =tail -n +2 | =awk '{print \$NF}'")) /////////////////////////////////////////////////////////////////////////////// resolveipaddr(L) // for line (L), resolve any ipaddr to hostname if (L) =~ "(.+)[[:space:]]([[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\. [[:digit:]]{1,3}\\.[[:digit:]]{1,3})(.*)" set (L) = "$1 $2 [" . =addr2host($2) . "]" . $3 endif /////////////////////////////////////////////////////////////////////////////// subnets 10.1.0 10.1.1 10.1.2 10.2.0 10.2.1 10.2.253 10.2.254 [...] rpcprgnum 836129415 rpcprtnum #if rouen 935 #elsif cadiz | stockholm 159 #else 638 #endif ip_address_piktmaster // the ip addr, in dotted decimal, of the master // control machine 123.111.222.101 ethernet_address_piktmaster 11:22:33:dd:ee:ff ip_address_local_domains // the ip addrs, in dotted decimal, of our // local domains 123.111.130|123.101.202|123.111.135|123.100.200 ip_address_sysadmins 123.111.222.102 // hamburg 123.111.222.103 // cadiz 123.111.222.104 // trondheim // in our files/hosts_deny_files.cfg, for the file /etc/hosts.deny, we might // have something like: // // #if vienna // ALL : ALL EXCEPT 111.222.100.200 =ip_address_sysadmins // // ... // // we might have something similar in our files/hosts_allow_files.cfg; // we might also use =ip_address_sysadmins when monitoring access logs, // filtering out the connects from =ip_address_sysadmins, and reporting // all the rest /////////////////////////////////////////////////////////////////////////////// ntpserver 123.222.111.222 /////////////////////////////////////////////////////////////////////////////// // dns stuff nameddir /var/lib/named zondir =nameddir/master zonttl $TTL 3600 namedfiles db.earlymusicradio.com db.earlymusicradio.net db.earlymusicradio.org db.earlymusicchicago.com db.earlymusicchicago.org db.earlymusichicago.com db.earlymusichicago.org db.pikt.net db.pikt.org ///////////////////////////////////////////////////////////////////////////////
For more examples, see Samples.