;; 
;;=====================================================================================----- 
;; 
;;FUNCTION         GetIPinfo() - DEPRECATED - Unsupported on W-7 & higher 
;; 
;;ACTION           Gathers a computers IP address, subnet mask, and default gateway on 
;;                 computers that do not support EnumIPinfo(). 
;; 
;;AUTHOR           Howard A. Bullock 
;; 
;;VERSION          1.1 - 2004/07/23 
;; 
;;HISTORY          1.0 - 2001/11/24 - Initial Release 
;;                 1.1 - 2004/07/23 - G.Barnas - first try the built-in EnumIpInfo() 
;; 
;;SYNTAX           $IPinfo = GetIPinfo() 
;; 
;;PARAMETERS       None 
;; 
;;REMARKS          This UDF complements EnumIPinfo() for computers where EnumIPinfo() 
;;                 does not work. 
;; 
;;RETURNS          An array of three elements: IP Address, Subnet Mask, and Default Gateway. 
;; 
;;DEPENDENCIES     OpenFile() 
;;                  by H. Bullock 
;; 
;; 
;;EXAMPLES 
;; 
;;                 $IPinfo = GetIPinfo() 
;;                 $IPaddr = $IPinfo[0] 
;;                 $SNmask = $IPinfo[1] 
;;                 $Gateway = $IPinfo[2] 
 
Function GetIPinfo(OPTIONAL $Element)
 
  Dim $IPinfo[3], $File, $RC, $FH, $Line, $Pos, $Loop, $IPAddr, $Idx
 
  $IPaddr = EnumIPinfo(0,0)
  If $IPaddr = '0.0.0.0' Or $IPaddr = ''
 
    $File = GetTmpFN('IP')
 
    If @inwin=1
      Shell '%comspec% /c ipconfig >"' + $File + '"'
    Else
      Shell 'winipcfg /batch "' + $File + '"'
    EndIf
 
    $FH = OpenFile($File, 'R')
 
    If @error = 0
      $Line=Readline($FH)
      $Loop = 1
      While(@ERROR = 0 and $Loop = 1)
 
        If InStr($Line, '. . . : ') > 0
 
          While(@ERROR = 0 and $Loop = 1)
            Select
            Case InStr($Line, 'IP Address') > 0
                     $pos = instr($Line, ':')
                     $IPinfo[0] = SubStr($Line, $Pos+2, 15)
 
            Case InStr($Line, 'Subnet Mask') > 0
                     $IPinfo[1] = SubStr($Line, $Pos+2, 15)
 
            Case InStr($Line, 'Default Gateway') > 0
                     $IPinfo[2] = SubStr($Line, $Pos+2, 15)
                     If $IPinfo[2] <> '0.0.0.0' and $IPinfo[2] <> ''
                        $Loop = 0
                     EndIf
 
            Endselect
 
            $Line=ReadLine($FH)
          Loop
 
        EndIf
 
        $Line = ReadLine($FH)
 
      Loop
 
      $RC=Close($FH)
      Del $File
 
    EndIf
  Else
    ; Only return the address associated with the Default Gateway (Primary Address) 
    $Loop = 1
    $Idx  = 0
    While($Loop = 1 And $Idx < 10)
      $IPinfo[0] = EnumIPinfo($Idx,0)
      $IPinfo[1] = EnumIPinfo($Idx,1)
      $IPinfo[2] = EnumIPinfo($Idx,3)
      If $IPinfo[2] <> '0.0.0.0' and $IPinfo[2] <> ''
        $Loop = 0
      EndIf
      $Idx = $Idx + 1
    Loop
  Endif
 
  ; Return an array or just one element 
  Select
  Case $Element = 1
    $GetIPinfo = $IPinfo[0]
  Case $Element = 2
    $GetIPinfo = $IPinfo[1]
  Case $Element = 3
    $GetIPinfo = $IPinfo[2]
  Case 1
    $GetIPinfo = $IPinfo
  EndSelect
 
Endfunction