<http://www.netikka.net/tsneti/info/tscmd133.php>
Copyright © 2003-2010 by Prof. Timo Salmi  
Last modified Sun 24-Oct-2010 13:18:18
Welcoming the user from 23.22.136.56
ec2-23-22-136-56.compute-1.amazonaws.com
www.netikka.net
On Sun 17-Dec-2017 21:40:25 local time

 
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

This extra part is not NT/2000/XP/.. CMD.EXE scripting but PHP (Hypertext preprocessed file) programming. It is, however, of interest for this particular item. If you look at the welcoming header box of the current page, you will observe your remote IP-information (and the date/time). The PHP code used is
  <?php
  $remoteaddr=$_SERVER['REMOTE_ADDR'];
  $remotename=gethostbyaddr($remoteaddr);
  $servername=$_SERVER['SERVER_NAME'];
  $today = getdate();
  $datetimen = substr($today[weekday],0,3) . " " . $today[mday] . "-" . substr("$today[month]",0,3) . "-" . $today[year] . " " . substr("00$today[hours]",-2) . ":" . substr("00$today[minutes]",-2) . ":" .substr("00$today[seconds]",-2);
  ?>

  :
  <TABLE BORDER="1" BGCOLOR="#99FFCC">
    <TR STYLE="background: #99FFCC">
      <TD>
        <FONT SIZE="-1">
        Welcoming the user from <?php echo $remoteaddr; ?><BR>
        <?php echo $remotename; ?><BR>
        <?php echo $servername; ?><BR>
        On <?php echo $datetimen; ?> local time
        </FONT>
      </TD>
    </TR>
  </TABLE>
  :

References/Comments:
  Ipconfig
  W3Schools PHP Tutorial
  The PHP Group PHP Manual