Page 1 of 2 12>
Topic Options
#26229 - 2002-07-31 06:18 PM IP detection in a batch file
Chewmanfoo Offline
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!! [Cool]

Top
#26230 - 2002-07-31 06:20 PM Re: IP detection in a batch file
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Have you tried the @IPADDRESSx macro yet?

Check it out.

Top
#26231 - 2002-07-31 06:24 PM Re: IP detection in a batch file
Chewmanfoo Offline
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
#26232 - 2002-07-31 06:28 PM Re: IP detection in a batch file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok, batch:
code:
ipconfig|find "IP"|find /c "10.0"
if "%errorlevel%"=="1" run_kix
exit

_________________________
!

download KiXnet

Top
#26233 - 2002-07-31 06:41 PM Re: IP detection in a batch file
Chris S. Offline
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
#26234 - 2002-07-31 06:45 PM Re: IP detection in a batch file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
chris, I also was thinking the nul.
thought he can figure that out himself.

also, don't know about his net stuff but he might have the default gateway as 10.0.x.x even for clients in the other ip-class...
then that does not work [Wink]
just wanted to make as sure.
your suggestion anyway does somewhat the same and still is shorter and does not output anything [Cool]
_________________________
!

download KiXnet

Top
#26235 - 2002-07-31 07:02 PM Re: IP detection in a batch file
Chewmanfoo Offline
Fresh Scripter

Registered: 2002-07-29
Posts: 19
Loc: Milpitas
AHHAHH you guys ROCK!! thanks
Top
#26236 - 2002-07-31 07:03 PM Re: IP detection in a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If you do a double pipe then the GW doesn't matter.

ipconfig | find /i "address" | find " 10."
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#26237 - 2002-07-31 07:06 PM Re: IP detection in a batch file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
les, you are sweet like allways... [Razz]
_________________________
!

download KiXnet

Top
#26238 - 2002-07-31 07:17 PM Re: IP detection in a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Just backing you up there bud... [Big Grin]

Not sure Chris noticed the double pipe and Chewmanfoo didn't say who ROCKS the best.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#26239 - 2002-07-31 07:19 PM Re: IP detection in a batch file
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I think its possible that we all ROCK. [Wink]
Top
#26240 - 2002-07-31 07:21 PM Re: IP detection in a batch file
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#26241 - 2002-07-31 07:28 PM Re: IP detection in a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Yeah, we all ROCK! The problem with threads like this is of insufficient feedback. We all like to know we ROCK but someone else that may be reading this thread (maybe even months from now) wouldn't know what the best and final solution was.

We often also toss out snippets of code without explaining what it does. That was why I offered a little more insight on Jooel's code and tossed a bit of variation.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#26242 - 2002-07-31 07:42 PM Re: IP detection in a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
HB,
This is not my first rodeo... been known to double pipe before (but didn't inhale). [Wink]
Jooel whas the first to use it in this thread and deserves the vote. I just pointed it out. As it stands I shamelessly begged for a vote on another thread to stay ahead of Jooel.

[ 31 July 2002, 19:43: Message edited by: LLigetfa ]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#26243 - 2002-07-31 07:48 PM Re: IP detection in a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What about the leading space in my variation on find? Does that deserve a vote or a mention?

"10.0." could possibly match on one of the legit subnets. the leading space insures only addresses starting with 10. hit.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#26244 - 2002-07-31 08:18 PM Re: IP detection in a batch file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
les, didn't see that!
or even ": 10.0."?

actually, I bet you have voted for me allready but I haven't voted you!
the reason is simple (not counting votes!):
I want to save my vote for the situation that someone I think deserves some amount of stars loses them or gets too much.

I start to vote more right when it's allowed change the rate.

actually, if someone gives vote, his current rating counts and later he may have higher rating, which should count then but it doesn't.
that's reason two.

so les,
I can comfort you, if I get ahead of you, I'll vote for you so you drop too much behind [Big Grin]
_________________________
!

download KiXnet

Top
#26245 - 2002-07-31 08:42 PM Re: IP detection in a batch file
Chewmanfoo Offline
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
#26246 - 2002-07-31 08:47 PM Re: IP detection in a batch file
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
To be honest, it might actually be less taxing to start a KiXtart script from the login server, do your checks in Kixtart and only if a login script needs to be run to then load a second script which would act as the login script. I think the impact would be about the same, namely barely noticable.
_________________________
There are two types of vessels, submarines and targets.

Top
#26247 - 2002-07-31 08:50 PM Re: IP detection in a batch file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
first:
if not "%errorlevel%" == "0" goto factory
is same as:
if "%errorlevel%"=="1" goto factory

also, try taking of the ">nul"
it can reset the errorlevel.
if this is the reason you can do:
@echo off
before the ipcheck

cheers½
_________________________
!

download KiXnet

Top
#26248 - 2002-07-31 08:52 PM Re: IP detection in a batch file
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I notice you're doing an OS check. Just want to point out that ipconfig isn't going to work on non-NT boxes.
Top
Page 1 of 2 12>


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

Who's Online
0 registered and 611 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.044 seconds in which 0.014 seconds were spent on a total of 13 queries. Zlib compression enabled.

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