Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Script Code Based on System Variable Priors to Logon

Posted on 2010-01-12
3
Medium Priority
?
277 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
  • 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 your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Screencast - Getting to Know the Pipeline

564 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