C:\_G\WWW\~ELISANET\INFO\tscmd133.html
<http://www.elisanet.fi/tsalmi/info/tscmd133.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Wed 7-Nov-2018 10:01:14

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



133} How do I get the current IP address, number and name?


  @echo off & setlocal enableextensions
  ::
  :: Test first

  ipconfig|find "IP Address">nul
  if %errorlevel% GTR 0 (
    echo Not connected
    goto :EOF)
  ::
  :: Get the current IP

  for /f "tokens=2 delims=:" %%i in (
    'ipconfig /all^|find "IP Address"'
    ) do set ip=%%i
  set ip=%ip: =%
  echo %ip%
  ::
  :: Look up the IP address on the name server

  for /f "tokens=2 delims=:" %%n in (
    'nslookup %ip%^|find "Name:"'
    ) do set name=%%n
  set name=%name: =%
  echo %name%
  endlocal & goto :EOF

The output might be e.g.
  D:\TEST>cmdfaq
  193.166.122.2
  reimari.uwasa.fi
or
  D:\TEST>cmdfaq
  Not connected


  @echo off & setlocal enableextensions
  ::
  :: Test first

  ipconfig|find "IPv4 Address">nul
  if %errorlevel% GTR 0 (
    echo Not connected
    goto :EOF)
  ::
  :: Get the current IP

  for /f "tokens=2 delims=:(" %%i in (
    'ipconfig /all^|find "IPv4 Address"'
    ) do set ip=%%i
  set ip=%ip: =%
  echo %ip%
  ::
  :: Look up the IP address on the name server

  for /f "tokens=2 delims=:" %%n in (
    'nslookup %ip%^|find "Name:"'
    ) do set name=%%n
  set name=%name: =%
  echo %name%
  endlocal & goto :EOF

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd133.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd133
http://www.elisanet.fi/tsalmi/info/tscmd133.html
file:///c:/_g/www/~elisanet/info/tscmd133.html