KiXrookie
(Fresh Scripter)
2003-09-23 05:50 PM
Ready ?

Can you please take a look at my script before I release? I wanted to use PPING to query any valid IPs on the Network and then use this script against the live workstations without them having to re-login. I started getting a headache so I finally conceded to putting this in the login script for the next time they login.

[CODE]

;This script will get the IP Address and version of Netware from a workstation then write it to a network share

Break on

;Get Cadre Version#
$Netware=ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\Novell","CurrentVersion")

;Get ComputerName
$computer=ReadValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName","ComputerName")

; First octet (169)...
$IP1 = LTRIM(SUBSTR(@IPADDRESS0, 1, 3))
; Second octet (54)...
$IP2 = LTRIM(SUBSTR(@IPADDRESS0, 5, 3))
; Third octet (88)...
$IP3 = LTRIM(SUBSTR(@IPADDRESS0, 9, 3))
; Fourth octet (1)...
$IP4 = LTRIM(SUBSTR(@IPADDRESS0, 13, 3))

; Show the 4 octets...
;? $IP1
;? $IP2
;? $IP3
;? $IP4

; Create MyIP from IP Address + Netware Version + ComputerName
$MyIP=$IP1 + "." + $IP2 + "." + $IP3 + "." + $IP4 + " " + $Netware + " " + $computer
;? $MyIP

;Check if MyIP already exists in ipadds.txt

shell '%comspec% /c find /i /c "$MyIP" "c:\kixtart\ipadds.txt"'
If @error = 0 goto end
else
RedirectOutput ("X:\kixtart\ipadds.txt") = 0
? $MyIp
endif

:end


KiXrookie
(Fresh Scripter)
2003-09-23 05:51 PM
Re: Ready ?

PS- I'll change the location of the results to a network share once it's ready to go.

Sealeopard
(KiX Master)
2003-09-23 05:55 PM
Re: Ready ?

Please read the TCP/IP primer in the FAQ Forum and use the IsStringInFile() UDF instead. Use the @WKSTA instead of a registry read.

KiXrookie
(Fresh Scripter)
2003-09-23 07:40 PM
Re: Ready ?

The @wksta and @ipaddress0 definitley makes it cleaner. I'm a little confused about using the IsStringInFile UDF as part of the script though.

Would the $filename=ipaddress0 and the $string=c:\kixtart\ipadds.txt

[CODE]

function IsStringInFile($filename,$string)

$isstringinfile=0 if $string=''
exit 87
endif

if not exist($filename)
exit 2
endif

shell '%COMSPEC% /e:1024 /c find /c /i "'+$string+'" "'+$filename+'" > nul'
if @ERROR=0
$IsStringInFile=1
endif
exit 0

endfunction


Sealeopard
(KiX Master)
2003-09-23 07:54 PM
Re: Ready ?

You'd use it to check whether the IP address is already in that file.

However, a .INI file with READPROFILESTRING/WRITEPROFILESTRING would be even more efficient as you'd do only one line to check whehter the IP address is already present, then a second line to write the IP address. Check out these two functions and the .INI file structure.


KiXrookie
(Fresh Scripter)
2003-09-23 11:21 PM
Re: Ready ?

Thanks for the advice, I'm in the process of testing the Read/Write ProfileString commands but in the meantime do you know why there is a 1 being appended to the previous line in my text file after another line is added?

[ipadds.txt]

165. 48. 73.169 4.90 B0000F6DD601B1
165. 48. 97.101 4.83 B0040811FB1E41
165. 48. 44.109 4.83 B0000412FE233


Les
(KiX Master)
2003-09-23 11:45 PM
Re: Ready ?

Yes I do! Unhandled return codes. It is all explained in the FAQ!

KiXrookie
(Fresh Scripter)
2003-09-24 11:16 PM
Re: Ready ?

Yep, Yep!! Got it resolved. I'll get there at some point.