📎 AI Summary:
The thread discusses methods to retrieve specific IP addresses on Windows systems, initially through a batch script. Users suggest that PowerShell offers a simpler solution, with examples provided, though there's some debate over the availability of PowerShell on older Windows versions. The conversation concludes with an alternative approach using JavaScript to obtain the public IP via an API. Overall, the discussion highlights various scripting options to efficiently obtain IP addresses, with a leaning toward PowerShell as the preferred method.

ilcress

New Member
Joined
Aug 18, 2020
Messages
2
Thread Author #1
Hi all!
i need, for improve a script, to get only a specific ipadress (i have multiple network connection).

This is the script, i pass the IP manually:
Code:
echo off
echo ==================================
echo ====     CONFIGURAZIONE        ===
echo ==================================
ipconfig|find "ipv4" /i
set /p IP=From what IP you want reach extinguisher application?   
echo IP choised is %IP%
SET INDIRIZZI=(10.1.2.3 10.1.2.4 OTHER_IP)
FOR %%A IN %INDIRIZZI% DO (
REM ECHO %%A
ROUTE ADD %%A  MASK 255.255.255.255 %IP% METRIC 2
)
cls
(((echo Done!) & echo Keep cmd with red background opened to show connections from sps subnet ) & echo.)|MSG *
color CF
netstat -ano 1 | findstr "10.15.*3389"
exit

in cygwin the command is:
Bash:
ipconfig | grep IPv4 | cut -d':' -f 2 | cut -d' ' -f 2 | grep 10.12.

Thanks from my heart!
 

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,995
Powershell will be alot easier than a batch file.
Code:
Function Get-IPAddress {
    param (
        [Parameter(Mandatory=$true)][int]$Interface
    )
    (Get-NetIPAddress -InterfaceIndex 8).IPAddress
}
Get-NetAdapter | Select ifIndex,Name,InterfaceDescription,Status | sort ifIndex
Get-IPAddress
 

Josephur

Windows Forum Admin
Staff member
Premium Supporter
Microsoft Certified Professional
Joined
Aug 3, 2010
Messages
1,283
If you are looking for public IP, in PowerShell:

Invoke-RestMethod api.ipify.org
 

Solution

ilcress

New Member
Joined
Aug 18, 2020
Messages
2
Thread Author #4
Powershell will be alot easier than a batch file.
Code:
Function Get-IPAddress {
    param (
        [Parameter(Mandatory=$true)][int]$Interface
    )
    (Get-NetIPAddress -InterfaceIndex 8).IPAddress
}
Get-NetAdapter | Select ifIndex,Name,InterfaceDescription,Status | sort ifIndex
Get-IPAddress
Thanks you Neemobeer! Unlukly not everybody has PS, there are some alternatives with cmd/batch?

Thanks
 

Neemobeer

Windows Forum Team
Staff member
Joined
Jul 4, 2015
Messages
8,995
Every Windows computer back to Windows 7 has powershell preloaded
 

Josephur

Windows Forum Admin
Staff member
Premium Supporter
Microsoft Certified Professional
Joined
Aug 3, 2010
Messages
1,283
Every Windows computer back to Windows 7 has powershell preloaded
You sure about that? I thought it was optional even in Windows 8?