14 October 2009

Logon Script To Attach To A Server Based On IP Address

Logon Script To Attach To A Server Based On IP Address

Info on both Kix and batch file commands to do things based on the IP address of the client.
Examples in case they get lost.
Kix:-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Establishes $location variable, determined by subnet
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
:IPCHECK
$address = @IPADDRESS0
$subnet = SubStr($address,9,3)
$subnet1 = SubStr($address,13,3)
Select
Case $subnet = "xxx" And $subnet1 >= "xxx" And $subnet1 <= "xxx"
$location = servername-1
"net use d: \\" & $location &"\" & @username &" /persistent"
Case (($subnet = "xxx" And $subnet1 >= "xxx" And $subnet1 <= "xxx") $location = servername2
"net use d: \\" & $location &"\" & @username & " /persistent"
EndSelect
or something to that effect...

Normal batch commands:-

@ECHO OFF
IF EXIST Z: NET USE Z: /DELETE > NUL
IPCONFIG | FIND "10.76.128." > NUL
IF ERRORLEVEL 1 GOTO NotInNet1
NET USE Z: \\server1\%username% > NUL
:NotInNet1
IPCONFIG | FIND "10.76.129." > NUL
IF ERRORLEVEL 1 GOTO NotInNet2
NET USE Z: \\server2\%username% > NUL
:NotInNet2
Original page is on http://www.adminscripteditor.com in the forums.
Thanks to bphilhower for the kix version and Witto for the batch commands.