Scripts and IP subnets.

Posted on 2003-03-18
Medium Priority
Last Modified: 2010-04-13
Is there any way of preventing login scripts from running when logging in from a specific IP subnet...??

I have location A & B. These locations are connected using VPN- tunnels.
When a user from location A takes a visit to location B with his laptop and logs in, the login script excecutes with a result in talking up all the bandwidth, because of antivrus updates and etc.

Can this be prevented?

Thx in advance..

Question by:Rubeck
  • 2

Accepted Solution

YarnoSG earned 375 total points
ID: 8159791
assuming NT/2000, your login script can include a check for the machine's own IP:

here is a script I wrote that puts the IP octets into individual variables, which you can then do whatever you want with;  it employs three different techniqes depending on your situation (one is active and two are commented out)

It is fully commented;  I wrote it while teaching a DOS class.

:: IpToVar.CMD
:: by Steven Yarnot
:: Last Modified 11/28/2001 Cleaned Up Code (redundant If Statements removed)
:: Batch for seting the individual octets of an Ip to variables;
:: Most helpful in environments with subnet mask  
:: for quickly retrieving subnet
:: Usage:  IpToVar TargetNode
:: Sets variables:     Oct1     first octet
::               Oct2     second octet          
::               Oct3     third octet
::               Oct4     fourth octet
:: works on NT and Win2000.
:: Three approaches to same problem:  one uses IPCONFIG, another NSLOOKUP and the Third
:: ping.  Ipconfig will be quicker if you are querying the local PC, and the Ping and NSLOOKUP approaches
:: can be used for remote pcs;  The ping approach can also identify Live clients

:: More Comments Added 11/28/2001 after walking my DOS class through this:
:: For Statment executes a single packet ping;  if successful, third line of response will contain
:: "Reply" in the %i variable.  This will make the IF statement valid.  the first Set will then execute
:: with %k as the data (first octet of IP), followed in succession by the remaining 3 octets.   Because
:: the "&&" is used, they will only be executed if the IF statement is successful.

@echo off

:: Set the OCT variables to a default value first if you are using this in a script;  with failed pings,
:: the OCT variables will not be set and so therefore would be what they were the last time unless you
:: give them a default.

set Oct1=off& Set Oct2=off& set Oct3=off& set Oct4=off

:: The Ping approach 1:

for /f "tokens=1,2,3,4,5,6 delims=:,. "  %%i in ('ping %1 -n 1') do if "%%i"=="Reply" set Oct1=%%k && set Oct2=%%l && set Oct3=%%m && set Oct4=%%n

:: The Ping approach 2: (DOES NOT DETERMINE IF OFF OR ON)

:: for /f "tokens=1,2,3,4,5,6,7,8,9 delims=[]:,. "  %%i in ('ping %1 -n 1') do if "%%i"=="Pinging" set Oct1=%%n && set Oct2=%%o && set Oct3=%%p && set Oct4=%%q

:: The nslookup approach:

:: for /f "tokens=1,2,3,4,5,6 delims=:,. "  %%i in ('nslookup %1') do if "%%i"=="Address" set Oct1=%%k && set Oct2=%%l && set Oct3=%%m && set Oct4=%%n

:: The IpConfig approach:
:: note there are tabs imbedded in the if statements;  edit with caution.

::for /f "tokens=1,2,3,4,5,6 delims=:,. "  %%i in ('ipconfig') do if "%%i"=="     IP" set Oct1=%%k && set Oct2=%%l && set Oct3=%%m && set Oct4=%%n

::Echo %1 %Oct1%  %Oct2%  %Oct3%  %Oct4% >> P:\iptovar.txt
:: Output to a A CSV by Subnet (assumes Subnet Mask)
echo %oct3%,%1,SMSServerName,LOC >> p:\PinglistSubn.CSV

once you have the octets in the variables, you can manipulate them with IF statements in a login script.

-Steven Yarnot

Expert Comment

ID: 8159803
Oh, and as to your problem;  you could have a "short and sweet" login script run by everybody, (this script is really only one line, with oodles and gobs of comments), and then branch to either the REAL login script or EXIT.


Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
"Day by day nothing changes but when u look back, everything is different". That quote precisely describes today’s digital era. For example, you may not have noticed the change, but Voice Search is now all around us.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question