#26229 - 2002-07-31 06:18 PM
IP detection in a batch file
|
Chewmanfoo
Fresh Scripter
Registered: 2002-07-29
Posts: 19
Loc: Milpitas
|
Okay, I have been given a puzzle to figure out and I need some help getting it solved. These are the details.
* We have two logical networks running in the same domain. * One network is running on multiple legit network subnets * The other is running on a private address ( 10.0.X.X) being NATed through a firewall. I have to come up with a way to have the script detect what IP the computer logging in is on. * If the computer is on the "10 net" then the script needs to abort, if it is not on the "10 net" then the computer will go and install kix, and run the rest of the KIX scripts.
HERE IS THE QUESTION: How do I get the computer to detect the IP in the batch file, so that it knows whether to proceed or not.
Here is a sample that I wrote and am having problems with. Help with this will be appreciated.
:Factorydetect %windir%\system32\ipconfig > %temp%\clientip.txt %systemroot%\ipconfig > %temp%\clientip.txt find "10.0." %temp%\clientip.txt /c /i IF not errorlevel 0 GOTO ostype
echo "Welcome to the Factory" sleep 2 goto end
Chewmanfoo PS: This bbs rocks and is on the top of my Favorites list!!
|
|
Top
|
|
|
|
#26231 - 2002-07-31 06:24 PM
Re: IP detection in a batch file
|
Chewmanfoo
Fresh Scripter
Registered: 2002-07-29
Posts: 19
Loc: Milpitas
|
Thats the problem, I have to do it in the batch file, and then once the subnet is detected, then I can have the computer install the kix client and run kix from either the server or the client.. etc. The factory is very picky about how they don't want anything installed on the machines or performance affected.
|
|
Top
|
|
|
|
#26233 - 2002-07-31 06:41 PM
Re: IP detection in a batch file
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Howsabout...
code:
@echo off ipconfig | find "10.0." > nul if "%errorlevel%" == "0" echo Found IP range
{edit} Doh! That'll teach me to go do something, come back, and hit the reply button. [ 31 July 2002, 18:43: Message edited by: Chris S. ]
|
|
Top
|
|
|
|
#26235 - 2002-07-31 07:02 PM
Re: IP detection in a batch file
|
Chewmanfoo
Fresh Scripter
Registered: 2002-07-29
Posts: 19
Loc: Milpitas
|
AHHAHH you guys ROCK!! thanks
|
|
Top
|
|
|
|
#26239 - 2002-07-31 07:19 PM
Re: IP detection in a batch file
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
I think its possible that we all ROCK.
|
|
Top
|
|
|
|
#26240 - 2002-07-31 07:21 PM
Re: IP detection in a batch file
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Les, I'd give you another vote for the double pipe if I could.
|
|
Top
|
|
|
|
#26245 - 2002-07-31 08:42 PM
Re: IP detection in a batch file
|
Chewmanfoo
Fresh Scripter
Registered: 2002-07-29
Posts: 19
Loc: Milpitas
|
Well, looks like we jumped over one hurdle only to land on another. This is the script that I am writing for the Batch file portion of the login. Looks like the error level isn't working for some reason, even if I put it above another errorlevel detect. I also went with the other direction. If there is an error, assume the machine is factory and abort the script. Once again, you guy's help is much appreciated.
Chewmanfoo
REM Init variables set KixCopy= set AV= set RAS=
REM ------------------------------- REM Check for connection type REM ------------------------------- ipconfig | find /i "address" | find " 172." > nul if not "%errorlevel%" == "0" goto factory
%0\..\checkras >nul if errorlevel 1 set RAS=YES
REM ------------------------------- REM End Check for connection type REM -------------------------------
:oscheck REM ------------------------------- REM Check for OS type REM ------------------------------- rem @echo off REM Batch file to detect operating system REM ---------------------------------- echo "Checking for machine type..." echo. echo. echo. IF "%OS%" == "Windows_NT" goto WinNT goto WIN9x
:WIN9x echo You are NOT running Windows NT (Windows 95/98 perhaps?) goto kixcheck
:WINNT REM %0\..\gettype.exe gettype.exe if errorlevel=9 goto FILENOTFOUND
echo You are running... REM echo More Specifically: echo.
if ERRORLEVEL=8 goto EIGHT if ERRORLEVEL=7 goto SEVEN if ERRORLEVEL=6 goto SIX if ERRORLEVEL=5 goto FIVE if ERRORLEVEL=4 goto FOUR if ERRORLEVEL=3 goto THREE if ERRORLEVEL=2 goto TWO if ERRORLEVEL=1 goto ONE
:FILENOTFOUND echo. echo Gettype not found. echo. goto END
:EIGHT echo Windows NT [Enterprise/Terminal] Server Non-Domain Controller goto END
:SEVEN echo Windows NT [Enterprise/Terminal] Server Domain Controller goto END
:SIX echo Windows 2000 Server Domain Controller. goto END
:FIVE echo Windows NT Server Domain Controller. goto END
:FOUR echo Windows 2000 Server Non-Domain Controller. goto END
:THREE echo Windows NT Server Non-Domain Controller. goto END
:TWO echo Windows 2000 Professional installation. goto kixcheck
:ONE echo Windows NT Workstation. goto kixcheck
:KiXCheck sleep 1 REM ------------------------------------------ REM Check for local KiXtart files REM ------------------------------------------ echo. echo Checking for local KiXtart files.. echo. if exist %WINDIR%\kix32.exe goto ClientKiX echo No local files found. echo. if "%KiXCopy%" == "1" goto ServerKiX echo Attempting to copy files to echo client for faster execution.... echo. copy %0\..\kix32.exe %WINDIR% >nul copy %0\..\kx*.dll %WINDIR% >nul set KixCopy=1 goto KiXCheck REM ------------------------------------------ REM End Check for local KiXtart files REM ------------------------------------------
:ClientKiX REM ------------------------------------------ REM Begin Running KiXtart Script from client REM ------------------------------------------ echo. echo Running KiXtart from client... echo. %WINDIR%\kix32 %0\..\logon.kix REM ------------------------------------------ REM End Running KiXtart Script from client REM ------------------------------------------ goto End
:ServerKiX REM ------------------------------------------ REM Begin Running KiXtart Script from server REM ------------------------------------------ echo. echo Running KiXtart from server... echo. %0\..\kix32 logon.kix REM ------------------------------------------ REM End Running KiXtart Script from server REM ------------------------------------------ goto End
:factory echo "Welcome to the Factory" sleep 2 goto end
:End
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 878 anonymous users online.
|
|
|