JSI Tip 5650. How do I determine the IP address of my computer, and parse it?


You can ping your computer name (%ComputerName%) to determine it's IP Address.

I have scripted $ip.bat to return the $ip1, $ip2, $ip3, and $ip4 environment variables. The syntax is call $ip.

$ip.bat contains:

@echo off
setlocal
For /f "Skip=1 Tokens=*" %%a in ('@ping -n 1 %computername%') do set line=%%a&call :ipa
endlocal&set $ip1=%$ip1%&set $ip2=%$ip2%&set $ip3=%$ip3%&set $ip4=%$ip4%
goto :EOF
:ipa
if /i not "%line:~0,7%"=="Pinging" goto :EOF
for /f "Tokens=2 Delims=\[\]" %%b in ('@echo %line%') do set ip=%%b
for /f "Tokens=1-4 Delims=." %%a in ('@echo %ip%') do set $ip1=%%a&set $ip2=%%b&set $ip3=%%c&set $ip4=%%d
To reconstitute the IP address:

set ip=%$ip1%.%$ip2%.%$ip3%.%$ip4%

If you know that there is a member server on your subnet with IP address xxx.xxx.xxx.001, and it contains a share you wish to map:

if exist <Drive:>\ net use <Drive:> /delete>nul
net use <Drive:> \\%$ip1%.%$ip2%.%$ip3%.1\MyShare>nul



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish