Page 1 of 1 1
Topic Options
#48254 - 1999-10-01 11:27 AM IP Address-I need a better script
Anonymous
Unregistered


We use the following script to determine the location of a PC and define a UNC's and drive letters and then run some commands based on the UNC's. Everything works fine, but I just feel like there has to be a better way. Does anyone know if there is a cleaner way to do this?

SELECT
CASE ($IP0 = "167. 64. 12." or $IP1 = "167. 64. 12." or
$IP0 = "167. 64. 24." or $IP1 = "167. 64. 24." or
$IP0 = "167. 64. 64." or $IP1 = "167. 64. 64." or
$IP0 = "167. 64.105." or $IP1 = "167. 64.105." or
$IP0 = "167. 64.111." or $IP1 = "167. 64.111." or
$IP0 = "167. 64.112." or $IP1 = "167. 64.112." or
$IP0 = "167. 64.115." or $IP1 = "167. 64.115." or
$IP0 = "167. 64.116." or $IP1 = "167. 64.116." or
$IP0 = "167. 64.168." or $IP1 = "167. 64.168." or
$IP0 = "167. 64.188." or $IP1 = "167. 64.188." or
$IP0 = "167. 64.237." or $IP1 = "167. 64.237.")
goto END

;Long Island City, NY
CASE $IP0 = " 10. 18. 3." or $IP1 = " 10. 18. 3."
$S="\\BFBF2PDC\"
$T="\\BFBF2PDC\"
goto SEAGATE

;Manhatten, NY
CASE $IP0 = " 10. 20. 2." or $IP1 = " 10. 20. 2."
$S="\\BFMH2BDC\"
$T="\\BFMH2BDC\"
goto SEAGATE

;Johnstown, PA - ****NO SERVER YET*****
;CASE $IP0 = " 10. 20. 1." or $IP1 = " 10. 20. 1."
; $S="\\BF????\"
; goto END

;Martinsville, VA
CASE $IP0 = " 10. 17. 5." or $IP1 = " 10. 17. 5."
$S="\\BWMV2DMS\"
$T="\\BWMV2DMS\"
goto SEAGATE

;PA
CASE $IP0 = " 10. 20. 4." or $IP1 = " 10. 20. 4."
$S="\\BWMV2DMS\"
$T="\\BWMV2DMS\"
goto SEAGATE

ENDSELECT

:SEAGATE
$V=$T+"WLAND\AGENTS\DOS_AG.COM /SW"
$W=$T+"WLAND\AGENTS\WIN_AG.EXE"

IF INGROUP ("NO_WINLAND") GOTO WINSTALL ENDIF
;** Determine Operating System 1 = Windows NT, 2 = Windows 95 **
if @inwin = 1
SHELL "%COMSPEC% /C START /W /MIN $V"
else
SHELL "%COMSPEC% /C START /W /M $V"
;SHELL "%COMSPEC% /C START $W"

:WINSTALL
IF INGROUP ("NO_WININSTALL") GOTO MAPX ENDIF
$Sea65Notins = "HKEY_LOCAL_MACHINE\SOFTWARE\OnDemand\WinINSTALL\Version 5.1\Applications"
$Sea65ins = "HKEY_LOCAL_MACHINE\SOFTWARE\Seagate Software\WinINSTALL\Version 6\Applications"
IF ExistKey("$Sea65NotIns") = 0
SHELL "$U1"
ENDIF

:END

EXIT

Top
#48255 - 1999-10-04 10:27 AM Re: IP Address-I need a better script
Anonymous
Unregistered


I have done the same thing with fairly simple code. Here is what I've done:

main kix script that gets launched for everyone in the company(there is some other stuff in this script too - ignore it):

law.kix:
----------------------
:RECHECK
$IP=@IPADDRESS0
$LASTIP=readvalue("HKEY_Local_Machine\Software\LAW\IPADDRESS","LASTIP")
if @error<>0 call localdef.kix goto RECHECK endif
if instr("$LASTIP","$IP")=0 call localdef.kix goto RECHECK endif
$HOMESERVER=readvalue("HKEY_Local_Machine\Software\LAW\HOMESERVER","HOMESERVER")
if @error<>0 call localdef.kix goto RECHECK endif
$LASTY2K=readvalue("HKEY_Local_Machine\Software\LAW\Y2K","Y2KOK")
IF @error=0
IF instr("$LASTY2K","YES")
GOTO SKIPY2KCHECK
ENDIF
ENDIF
call checkie.kix
:SKIPY2KCHECK
if $HOMESERVER="skip" exit endif
run "net time \\$HOMESERVER /set /yes"
SELECT
CASE $HOMESERVER="Atlanta-1"
GOTO NORTONNAVUP
CASE $HOMESERVER="Lawrenceville-1"
GOTO NORTONNAVUP
CASE 1
ENDSELECT
exit
:NORTONNAVUP
run "\\$HOMESERVER\desktop$$\navnet32\navup\navadmin\nav32up.exe \\$HOMESERVER\desktop$$\navnet32\navup\navadmin\navup.nns"
exit

-------------------------
Here is the local definition script (the reason that they are in two files is so that this longer script does not have to be called unless their IP has changed(i.e. a laptop)

localdef.kix
-------------------------
$IP=@IPADDRESS0
$LEN=len("$IP")
$NWA=substr($IP,9,$LEN-8)
$POS=instr($NWA,".")
$NAP=substr($NWA,1,$POS-1)
$NA=ltrim("$NAP")
SELECT
CASE instr("10-11","$NA")>0
$HS="Albany-1"
CASE instr("63-64","$NA")>0
$HS="Asheville-1"
CASE instr("16-17-18-19","$NA")>0
$HS="Atlanta-1"
CASE instr("26-27","$NA")>0
$HS="Austin-1"
CASE instr("30-31","$NA")>0
$HS="Baltimore-1"
CASE instr("38-39","$NA")>0
$HS="Birmingham-1"
CASE instr("72-73","$NA")>0
$HS="Boston-1"
CASE instr("36-37","$NA")>0
$HS="Canton-1"
CASE instr("32-33","$NA")>0
$HS="Charleston-1"
CASE instr("45-46-47","$NA")>0
$HS="Charlotte-1"
CASE instr("65-66","$NA")>0
$HS="Chattanooga-1"
CASE instr("236-237","$NA")>0
$HS="Chicago-1"
CASE instr("246-247","$NA")>0
$HS="Cincinnati-1"
CASE instr("50-51","$NA")>0
$HS="Columbia-1"
CASE instr("187-188-189-190","$NA")>0
$HS="Corporate-1"
CASE instr("54-55","$NA")>0
$HS="Dallas-1"
CASE instr("69-70","$NA")>0
$HS="Ftworth-1"
CASE instr("173-174","$NA")>0
$HS="Gainesville-1"
CASE instr("214-215","$NA")>0
$HS="Greensboro-1"
CASE instr("218-219","$NA")>0
$HS="Greenville-1"
CASE instr("58-59-60-61-62","$NA")>0
$HS="Houston-1"
CASE instr("220-221","$NA")>0
$HS="Jackson-1"
CASE instr("70-71","$NA")>0
$HS="Jacksonville-1"
CASE instr("74-75-76-77-78-79-80-81-82-83-84-85-86-87-88-89-90-91-92-93-94-95-96-97-98-99","$NA")>0
$HS="Kennesaw-1"
CASE instr("234-235","$NA")>0
$HS="Knoxville-1"
CASE instr("14-15","$NA")>0
$HS="Lawrenceville-1"
CASE instr("248-249","$NA")>0
$HS="Lexington-1"
CASE instr("122-123-124-125-126-127","$NA")>0
$HS="Losangeles-1"
CASE instr("134-135-136-137","$NA")>0
$HS="Louisville-1"
CASE instr("142-143","$NA")>0
$HS="Miami-1"
CASE instr("40-41","$NA")>0
$HS="Milwaukee-1"
CASE instr("240-241","$NA")>0
$HS="Naples-1"
CASE instr("144-145","$NA")>0
$HS="Nashville-1"
CASE instr("150-151","$NA")>0
$HS="Newyork-1"
CASE instr("154-155","$NA")>0
$HS="Norfolk-1"
CASE instr("162-163","$NA")>0
$HS="Orlando-1"
CASE instr("34-35","$NA")>0
$HS="Beltsville-1"
CASE instr("170-171-172","$NA")>0
$HS="Phoenix-1"
CASE instr("178-179","$NA")>0
$HS="Raleigh-1"
CASE instr("156-157","$NA")>0
$HS="Richmond-1"
CASE instr("202-203","$NA")>0
$HS="Sandiego-1"
CASE instr("160-161","$NA")>0
$HS="SanJuan-1"
CASE instr("164-165","$NA")>0
$HS="Savannah-1"
CASE instr("222-223-224-225","$NA")>0
$HS="Tampa-1"
CASE instr("28-29","$NA")>0
$HS="Tulsa-1"
CASE instr("230-231-232-233","$NA")>0
$HS="Washington-1"
CASE instr("67-68","$NA")>0
$HS="Westpalm-1"
CASE instr("244-245","$NA")>0
$HS="Wilmington-1"
CASE 1
$HS="skip"
MESSAGEBOX("This Login Script was not able to determine your Home Server. Please contact Helpdesk and let them know that you got this message. Your virus definitions and engine will not be updated until this is resolved.","Login Script Error - 'Can Not Determine Home Server'",16)
ENDSELECT
$HOMESERVER=$HS
$RC=existkey("HKEY_Local_Machine\Software\LAW")
if $RC<>0 Addkey("HKEY_Local_Machine\Software\LAW") endif
$RC=existkey("HKEY_Local_Machine\Software\LAW\HOMESERVER")
if $RC<>0 Addkey("HKEY_Local_Machine\Software\LAW\HOMESERVER")
WRITEVALUE("HKEY_Local_Machine\Software\LAW\HOMESERVER","HOMESERVER","$HOMESERVER","REG_SZ")
$RC=existkey("HKEY_Local_Machine\Software\LAW\IPADDRESS")
if $RC<>0 Addkey("HKEY_Local_Machine\Software\LAW\IPADDRESS")
WRITEVALUE("HKEY_Local_Machine\Software\LAW\IPADDRESS","LASTIP","$IP","REG_SZ")
return
-------------------------

So what I'm basically doing here, is keeping the main script very short (to improve time). I am also using the registry to cache values so that I can keep from calling up the longer scripts unless they really are needed to be pulled up. I know that there is a lot here, so if you need more explanation then I'll explain better. Sorry that there are not any comments in the script. Every byte counts over a slow wan link!

------------------
Gary Siepser, MCSE
LAWGIbb Group, Inc.
gsiepser@lawco.com

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.085 seconds in which 0.061 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org