Windows 10 Get only current IP

ilcress

New Member
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

Cyber Security Engineer
Staff member
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
If you are looking for public IP, in PowerShell:

Invoke-RestMethod api.ipify.org
 

ilcress

New Member
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
 
Top