[awk] Fonctions DNS

Bruno Bonfils asyd at asyd.net
Tue Aug 31 11:11:05 CEST 2010


Ci dessous des méthodes awk permettant de résoudre un nom en IP et vice
versa :

--8<--
function ipToName(address) {
   cmd="host " address
   while ((cmd | getline line) > 0) {
      if (line ~ /pointer/) {
         sub(".*pointer ", "", line)
         sub("\.$", "", line)
         return line
      } else { 
         return address
      }  
   }
}        

function nameToIp(name) {
   cmd="host " name
   while ((cmd | getline line) > 0) {
      if (line ~ /pointer/) {
         sub(".*address ", "", line)
         return line
      } else {
         return name
      }
   }
} 
--8<--
-- 
http://asyd.net/home/    - Home Page
http://www.guses.org/    - French Speaking (Open)Solaris User Group
http://netvibes.com/asyd - Portal


More information about the Shell mailing list