Last change
on this file since 30037 was 30037, checked in by ak19, 9 years ago |
Moving new scripts to GS3/bin/script instead of cluttering top level folder
|
-
Property svn:executable
set to
*
|
File size:
1.1 KB
|
Line | |
---|
1 | @echo off
|
---|
2 | for /f "usebackq tokens=2 delims=:" %%a in (`ipconfig ^| find "IPv4"`) do (set result=%%a)
|
---|
3 |
|
---|
4 | :: To lop off extra space in front of IPv4 number, end with:
|
---|
5 | ::do (set result=%a& echo %result:~1%)
|
---|
6 | :: Alternative: for /f "tokens=2 delims=:" %a in ('ipconfig ^| findstr /C:"IPv4 Address"') do echo %a
|
---|
7 | :: still need to remove space up front for that too.
|
---|
8 |
|
---|
9 | :: removes extra space in front
|
---|
10 | set result=%result:~1%
|
---|
11 |
|
---|
12 | :: The above produces the IPv4 number, e.g. 100.200.300.45
|
---|
13 | :: Still need to replace . with \.
|
---|
14 | :: http://scripts.dragon-it.co.uk/scripts.nsf/docs/batch-search-replace-substitute!OpenDocument&ExpandSection=3&BaseTarget=East&AutoFramed
|
---|
15 | :: Syntax: %string:SEARCH=REPLACE%
|
---|
16 | set result=%result:.=\.%
|
---|
17 |
|
---|
18 | :: http://stackoverflow.com/questions/2541767/what-is-the-proper-way-to-test-if-variable-is-empty-in-a-batch-file-if-not-1
|
---|
19 | :: Make sure it is not the empty string or a string of spaces
|
---|
20 | :: Test by setting result to space
|
---|
21 | ::set result=
|
---|
22 | set result=%result: =%
|
---|
23 |
|
---|
24 | ::if not "%result%" == ""
|
---|
25 | ::set result=^|%result%
|
---|
26 |
|
---|
27 | :: Echo a vertical bar up front, regardless of whether the result is empty
|
---|
28 | echo ^|%result% |
---|
Note:
See
TracBrowser
for help on using the repository browser.