We have multiple locations at work, all using a class 'C' address space
(192.168.xxx.xxx - don't ask why they didn't use a 172.16.x.x space -
who knows? ) Anyway - corp office downtown might be 192.168.96.1-255,
the plant across town might be 192.168.111.1-255, another location in
another city might be 192.168.97.1-255, etc....
What I'm trying to come up with is a reliable means of extracting the
3rd octect, which could be either 2 or 3 digits depending the site.
A .cmd file that I'm playing with right now leaves me with an env var of
%IP1% which is perfect as it is the IP of <X> machine. I want to know
where specifically that machine is from, and one way I can determine
that is by it IP address - specifically in the 3rd octect. ( I want to
do some logging via a logon script )
Anything that this will be run against will be XP or 2K3.
Any ideas??
Thanks folks...
-=- jd -=-
> the plant across town might be 192.168.111.1-255, another location in
> another city might be 192.168.97.1-255, etc....
> What I'm trying to come up with is a reliable means of extracting the
> 3rd octect, which could be either 2 or 3 digits depending the site.
@echo off & setlocal enableextensions
:: For demonstration testing a default is included
if "%~1"=="" (
set myip=192.168.97.255
) else (
set myip=%~1)
::
:: Get your third octet
for /f "tokens=3 delims=." %%i in ('echo %myip%') do set myip3=%%i
echo %myip%
echo %myip3%
endlocal & goto :EOF
The output
C:\_D\TEST>cmdfaq
192.168.97.255
97
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip
Thanks again! ;)
-=- jd -=-
Hello, colleagues!
Let to continue the thread?
I have variable VAR, containing a line of a kind:
" word1 word2 word3 ". (I.e. three strings of the symbols divided by
blanks)
My task is to allocate sub-string " word2 word3 ", i.e. it is necessary
for me to receive the second and third strings of symbols from VAR.
Example:
[begin of my bat-file]
set var =qwerty asdfgh zxcvbn
...
[Here your offers are realized !]
...
echo %var%
[end of my bat-file]
The output must be:
asdfgh zxcvbn
Thanks.