;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       NSLookup() 
;; 
;;ACTION         Returns a name/address pair, given a name or address 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.2  - 2016/03/04 
;; 
;;HISTORY        1.0  - 2007/10/10 - Original release 
;;               1.1  - 2014/07/15 - added optional SERVER parameter 
;;               1.2  - 2016/03/04 - Provided ability to specify IPV4/V6 retults 
;;                                  Changed format to delimit multiple IPs with ";" 
;; 
;;SYNTAX         NSLookup(ID [, SERVER] [, 4|6) 
;; 
;;PARAMETERS     ID - REQUIRED - String 
;;               - The host name or IP address to resolve 
;; 
;;		 SERVER - OPTIONAL - String 
;;               - DNS server IP to target the query to 
;; 
;;               4|6 - OPTIONAL - Number 
;;               Restrict the IP address returned to IPV4 or IPV6 format. Default 
;;               is to return both, delimited with a semicolon (;). 
;; 
;;REMARKS        Used to lookup IP from a name, or name from an IP 
;; 
;;RETURNS        String - hostname,IP pair, multiple sets delimited with semicolon (;) 
;;		 Returns a hostname/ip address pair, delimited by a comma 
;;		 if the named host resolves in DNS, otherwise a null string 
;;               If multiple IPs are returned, they are delimited with a semicolon (;) 
;; 
;;DEPENDENCIES   WScript 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES        
; 
Function NSLookup($_ID, OPTIONAL $_Server, $_IPVer)
 
  Dim $_sR			; Return string 
  Dim $_oExec			; WScript object 
  Dim $_aList, $_I		; list of IP values 
  Dim $_sIp			; IP list 
  Dim $_D			; delim 
 
  If $_Server $_Server = ' ' + $_Server EndIf			; preface with space if defined 
 
  ; Use WScript to execute the command and check the result 
  $_oExec = CreateObject("WScript.Shell").Exec('nslookup ' + $_ID + $_Server)
  If Not VarType($_oExec) = 9
    $NSLookup = ''
    Exit 10
  EndIf
 
  ; get the command result and extract what is needed 
  $_sR = Trim(Split(Join(Split($_oExec.StdOut.ReadAll, @CRLF), ''),'Name:')[1]) 
 
  ; process the return string 
  If Not $_sR
    $NSLookup = ''
    Exit 67
  Else
    If InStr($_sR, 'Addresses:')
      If $_IPVer
        $_sIp = ''
        $_aList = Split(Trim(Split($_sR, 'Addresses:')[1]), ' ')
        For Each $_I in $_aList
          Select
           Case $_IPVer = 4
            If InStr($_I, '.')
              $_sIp = $_sIp + $_D + Trim($_I)
              $_D = ';'
            EndIf
           Case $_IPVer = 6
            If InStr($_I, ':')
              $_sIp = $_sIp + $_D + Trim($_I)
              $_D = ';'
            EndIf
          EndSelect
        Next
        $NSLookup = Split($_sR, 'Addresses:')[0] + ',' + $_sIp
      Else
        $_sIp = ''
        $_aList = Split(Trim(Split($_sR, 'Addresses:')[1]), ' ')
        For Each $_I in $_aList
          If InStr($_I, '.') Or InStr($_I, ':')
            $_sIp = $_sIp + $_D + Trim($_I)
            $_D = ';'
          EndIf
        Next
        $NSLookup = Split($_sR, 'Addresses:')[0] + ',' + $_sIp
        ;$NSLookup = Split($_sR, 'Addresses:')[0] + ',' + Trim(Split($_sR, 'Addresses:')[1]) 
      EndIf
    Else
      $NSLookup = Split($_sR, 'Address:')[0] + ',' + Trim(Split($_sR, 'Address:')[1])
    EndIf
    Exit 0
  EndIf
 
EndFunction