?
Solved

Script Code Based on System Variable Priors to Logon

Posted on 2010-01-12
3
Medium Priority
?
276 Views
Last Modified: 2012-05-08
Does anyone know of a way to create a batch command script to determine an IP address and then test for it? or another batch command that will determine a host (computer) location based on information that would be available prior to logging -- such as IP Address. We have used %logonserver% in the past, but this is determined after the user logs in, we need something to define a computer (host) location prior to the user logging in.  We do not want to use VB Script though.
0
Comment
Question by:danielsd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 38

Assisted Solution

by:Shift-3
Shift-3 earned 664 total points
ID: 26294922
Here's one way to do it, finding the machine's IP address using IPCONFIG.

@echo off
setlocal enabledelayedexpansion
 
for /f "tokens=2 delims=:" %%G in ('ipconfig ^| find "IP Address"') do (
 for %%H in (%%G) do set ip=%%H
 echo !ip!
)

Open in new window

0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 1336 total points
ID: 26295117
Other scripts I use based on IP to get the subnet etc. for such things is:

@echo off
for /f "tokens=2 delims=:" %%a in ('ipconfig ^|find "IP Address"') do call :process %%a & goto :next
:next
echo Subnet is %subnet% and host is %host%
if not "%subnet%"=="192.168.0" route add x.x.x.x 255.255.255.255 %subnet%.1 METRIC 3

goto :Eof

:process
echo Gateway found at %1
for /f "tokens=1-4 delims=." %%a in ("%1") do set subnet=%%a.%%b.%%c & set host=%%d


or this one that adds a route if not on a certain subnet for instance

@echo off
for /f "tokens=2 delims=:" %%a in ('ipconfig ^|find "IP Address"') do call :process %%a & goto :next
:next
echo Subnet is %subnet% and host is %host%
if not "%subnet%"=="192.168.0" route add x.x.x.x 255.255.255.255 %subnet%.1 METRIC 3

goto :Eof

:process
echo Gateway found at %1
for /f "tokens=1-4 delims=." %%a in ("%1") do set subnet=%%a.%%b.%%c & set host=%%d
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 1336 total points
ID: 26295133
Or more simply:

@echo off
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find /i "IP Address"') do set ipaddr=%%a
for /f "tokens=1,2,3 delims=. " %%a in ('echo %ipaddr%') do set subnet=%%a.%%b.%%c
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Simple Linear Regression
Suggested Courses

777 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