Created
August 16, 2022 10:25
-
-
Save avipars/62f51b9c90a1312b8f1a685832f7b93b to your computer and use it in GitHub Desktop.
IP Tracking and Whitelist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-Location -Path "C:\temp" #any main directory | |
$uri = "https://whatismyip.host/ip4" #any website which can provide an IPV4 in text form | |
#old http://ifconfig.me/ip | |
$ipv4 = (Invoke-WebRequest -uri $uri).Content #gets the public IP | |
$currentip = "1.2.3.4" #initial IP to start with | |
$val = $true | |
$exists = $false | |
$powershell = "iplist.txt" #the text file for storing addresses | |
Invoke-Item $powershell | |
$file = Get-Content $powershell #opens it in notepad | |
:loop1 while ($val){ | |
$containsWord = $file | %{$_ -match $ipv4} | |
if ($containsWord -contains $true) #if the ip is in the list | |
Write-Output "same IP - $ipv4" | |
$val = $true | |
Start-Sleep -Seconds 1500 #sleep for 25 minutes | |
$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) #beeps | |
#now here is where you can have it add your ip to a whitelist or log it, etc. | |
$Response = Invoke-WebRequest -Uri "example.com" #get request | |
Write-Output $Response.StatusCode #check results | |
break loop1 #stops the loop | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment