JSI Tip 8232. How can I enumerate the local LAN IP address of my computer, but NOT IP addresses for other connections?


When you type IPCONFIG /ALL on a computer with multiple connections, multiple IP addresses are returned.

I have scripted LANIP.bat to return theĀ  IP address that matches a user specified mask, or masks.

The syntax for using LANIP.bat is:

LANIP IpMask \[IpMask ... IpMask\]

Where each IpMask uniquely identifies the IP address that you wish to enumerate.

If your local LAN ip addresses start with 192.168.0 or 192.168.1, you would use:

lanip 192.168.0 192.168.1

NOTE: If you knew that there were no nnn.192.168.xxx addresses, you could use lanip 192.168. instead. You can enumerate as many ranges as you wish by using the appropriates masks.

LANIP.bat contains:

@echo off
If \{%1\}

\{\} @echo Syntax LANIP IpMask \[IpMask ... IpMask\]&goto :EOF setlocal ENABLEDELAYEDEXPANSION set ipmask=%1 :loop shift if \{%1\}

\{\} goto find set ipmask=%ipmask% %1 goto loop :find for /f "Tokens=1* Delims=:" %%a in ('ipconfig /all^|Findstr /I /C:"IP Address"^|findstr "%ipmask%"') do ( set ip=%%b set ip=!ip: =! @echo !ip! ) ) endlocal



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