|
|
|
| 5 April 2002 | GetIPinfo() |
| Author | Howard A. Bullock |
| Action | Gathers a computers IP address, subnet mask, and default gateway on computers that do not support EnumIPinfo(). |
| Syntax | GetIPinfo () |
| Parameters | |
| 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 | Ipconfig.exe on NT 4.0 Winipcfg.exe on Win9x |
| Examples | $IP = "192.163.0.4" $SMmask = "255.255.255.128" $LogicalSubnet = CalcLogicalSubnet ($IP, $SNmask) call "$LogicalSubnet.kix" ;call "192.163.0.0.kix" $IP = "192.163.0.150" $SMmask = "255.255.255.128" $LogicalSubnet = CalcLogicalSubnet ($IP, $SNmask) call "$LogicalSubnet.kix" ;call "192.163.0.128.kix" |
| Source |
FUNCTION GetIPinfo ()
DIM $ipinfo[3], $file, $rc, $line, $pos, $loop
DIM $fh
writelog("Gathering IP info using GetIPinfo()")
$file = "%temp%\junk.txt"
IF @inwin = 1
SHELL "%comspec% /c ipconfig >$file"
ELSE
SHELL "winipcfg /batch $file"
ENDIF
$fh=1
$rc=Open($fh, $file, 2)
WHILE ($rc = -3)
$fh=$fh+1
$rc=Open($fh, $file, 2)
LOOP
IF $rc = 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
$getipinfo = $ipinfo
ENDFUNCTION ; - GetIPinfo -
|
|
|
|