Skip to content

Instantly share code, notes, and snippets.

@avipars
Created March 30, 2021 06:58
Show Gist options
  • Save avipars/e1f07cc325fba52625b07886e28e4b76 to your computer and use it in GitHub Desktop.
Save avipars/e1f07cc325fba52625b07886e28e4b76 to your computer and use it in GitHub Desktop.
Powershell detect if current IP is different than your previous one
$uri = "https://whatismyip.host/ip4"
$ipv4 = (Invoke-WebRequest -uri $uri).Content
$currentip = "your.current.public.ip4"
$val = $true
:loop while ($val) {
if($ipv4 -ne $currentip){
Write-Output "not equal - $ipv4 vs $currentip"
$val = $false
[console]::beep(500,300)
break loop
}
else{
Write-Output "same IP - $ipv4"
$val = $true
Start-Sleep -Seconds 500
}
}
@avipars
Copy link
Author

avipars commented Apr 2, 2021

$uri = "https://whatismyip.host/ip4"
#old http://ifconfig.me/ip

$ipv4 = (Invoke-WebRequest -uri $uri).Content

$currentip = "5.29.26.5"
$val = $true
$exists = $false
$powershell = "IP-whitelist\iplist.txt"
$file = Get-Content $powershell

:loop1 while ($val){
$containsWord = $file | %{$_ -match $ipv4}
if ($containsWord -contains $true) {
Write-Output "same IP - $ipv4"
$val = $true
Start-Sleep -Seconds 500
$exists = $true
$val = $true

} else {
    Write-Output "not equal - $ipv4 vs $currentip"
    Set-Clipboard -Value $ipv4
    $exists = $false
    Add-Content $powershell "$ipv4"
    [console]::beep(500,300)
    break loop1
}

}

<#
:loop while ($val) {
if($ipv4 -ne $currentip){
Write-Output "not equal - $ipv4 vs $currentip"
Set-Clipboard -Value $ipv4

    $val = $false
    [console]::beep(500,300)
    break loop
    $currentip = $ipv4
}
else{
    Write-Output "same IP - $ipv4"
    $val = $true
    Start-Sleep -Seconds 500
}

}

#Invoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content

#>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment