- 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:
in cygwin the command is:
Thanks from my heart!
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!
Solution
If you are looking for public IP, in PowerShell:
Invoke-RestMethod api.ipify.org
Invoke-RestMethod api.ipify.org
- Joined
- Jul 4, 2015
- Messages
- 8,998
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
- Thread Author
-
- #4
Thanks you Neemobeer! Unlukly not everybody has PS, there are some alternatives with cmd/batch?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
- Joined
- Aug 3, 2010
- Messages
- 1,289
You sure about that? I thought it was optional even in Windows 8?Every Windows computer back to Windows 7 has powershell preloaded
- Joined
- Jul 4, 2015
- Messages
- 8,998
What is Windows PowerShell? - PowerShell
This article explains the difference between Windows PowerShell and PowerShell.
docs.microsoft.com
vikasjkn
New Member
- Joined
- Dec 22, 2020
- Messages
- 1
You can also directly get IP using Javascript code simply calling API like
JavaScript:
$.getJSON("https://api.ipify.org?format=json", function (data) {
alert(IP: " + data.ip + ");
})