From fc4fd23289e50f9b13afbd19140e3c14e61873ff Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 28 Jan 2024 03:02:30 +0100 Subject: [PATCH] Fix --- src/PublicIP/private/common.ps1 | 2 -- src/PublicIP/public/Get-GeoLocation.ps1 | 27 ------------------ src/PublicIP/public/Get-IPConfig.ps1 | 26 ------------------ src/PublicIP/public/Restore-IPConfig.ps1 | 15 ---------- src/PublicIP/public/Save-IPConfig.ps1 | 35 ------------------------ 5 files changed, 105 deletions(-) delete mode 100644 src/PublicIP/public/Get-GeoLocation.ps1 delete mode 100644 src/PublicIP/public/Get-IPConfig.ps1 delete mode 100644 src/PublicIP/public/Restore-IPConfig.ps1 delete mode 100644 src/PublicIP/public/Save-IPConfig.ps1 diff --git a/src/PublicIP/private/common.ps1 b/src/PublicIP/private/common.ps1 index 727de53..a58fa50 100644 --- a/src/PublicIP/private/common.ps1 +++ b/src/PublicIP/private/common.ps1 @@ -2,5 +2,3 @@ MyIP = 'https://api.myip.com/' IPInfo = 'https://ipinfo.io/json' } - -$script:IPConfigFilePath = "$([Environment]::GetFolderPath('MyDocuments'))\IPConfig.json" diff --git a/src/PublicIP/public/Get-GeoLocation.ps1 b/src/PublicIP/public/Get-GeoLocation.ps1 deleted file mode 100644 index d81dd95..0000000 --- a/src/PublicIP/public/Get-GeoLocation.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -function Get-GeoLocation { - <# - .SYNOPSIS - Gets the current location of the device. - - .DESCRIPTION - Gets the current location of the device. - - .EXAMPLE - Get-GeoLocation - #> - - Add-Type -AssemblyName System.Device #Required to access System.Device.Location namespace - $GeoWatcher = New-Object System.Device.Location.GeoCoordinateWatcher #Create the required object - $GeoWatcher.Start() #Begin resolving current locaton - - while (($GeoWatcher.Status -ne 'Ready') -and ($GeoWatcher.Permission -ne 'Denied')) { - Start-Sleep -Milliseconds 100 #Wait for discovery. - } - if ($GeoWatcher.Permission -eq 'Denied') { - Write-Error 'Access Denied for Location Information' - } else { - $Location = $GeoWatcher.Position.Location | Select-Object Latitude, Longitude #Select the relevent results. - } - $GeoWatcher.Stop() - return $Location -} diff --git a/src/PublicIP/public/Get-IPConfig.ps1 b/src/PublicIP/public/Get-IPConfig.ps1 deleted file mode 100644 index f5303bb..0000000 --- a/src/PublicIP/public/Get-IPConfig.ps1 +++ /dev/null @@ -1,26 +0,0 @@ -function Get-IPConfig { - <# - .SYNOPSIS - Gets the current IP configuration. - - .DESCRIPTION - Gets the current IP configuration. - - .EXAMPLE - Get-IPConfig - #> - - $PublicIP = Get-PublicIP - $Time = Get-Date -Format yyyyMMdd-hhmmss.fffff - $Location = Get-GeoLocation - $LocalIPConfig = Get-NetIPAddress -AddressFamily IPv4 -Type Unicast | Where-Object PrefixOrigin -Match dhcp - $IPObj = [ordered]@{ - PublicIP = $PublicIP.IP - PrivateIP = $LocalIPConfig.IPv4Address - PCName = $ENV:COMPUTERNAME - Time = $Time - Latitude = $Location.Latitude - Longitude = $Location.Longitude - } - return $IPObj -} diff --git a/src/PublicIP/public/Restore-IPConfig.ps1 b/src/PublicIP/public/Restore-IPConfig.ps1 deleted file mode 100644 index 5216602..0000000 --- a/src/PublicIP/public/Restore-IPConfig.ps1 +++ /dev/null @@ -1,15 +0,0 @@ -function Restore-IPConfig { - <# - .SYNOPSIS - Restores the IPConfig from the file. - - .DESCRIPTION - Restores the IPConfig from the file. - - .EXAMPLE - Restore-IPConfig - #> - if (Test-Path -Path $IPConfigFilePath) { - return Get-Content -Path $IPConfigFilePath | ConvertFrom-Json - } -} diff --git a/src/PublicIP/public/Save-IPConfig.ps1 b/src/PublicIP/public/Save-IPConfig.ps1 deleted file mode 100644 index b98e77f..0000000 --- a/src/PublicIP/public/Save-IPConfig.ps1 +++ /dev/null @@ -1,35 +0,0 @@ -function Save-IPConfig { - <# - .SYNOPSIS - Saves the current public ip to a file. - - .DESCRIPTION - Saves the current public ip to a file. - If the file does not exist, it will be created. - - .EXAMPLE - Save-IPConfig - #> - $IPConfig = @() - $RestoredIPConfig = Restore-IPConfig - if ($null -ne $RestoredIPConfig) { - $IPConfig += $RestoredIPConfig - } - $CurrentIPConfig = Get-IPConfig - - # Check if recent and current ip is the same - if ($IPConfig[-1].PublicIP -eq $CurrentIPConfig.PublicIP) { - - } else { - "Public IP has changed since $($IPConfig[-1].Time)" - "Old PIP: $($IPConfig[-1].PublicIP)" - "New PIP: $($CurrentIPConfig.PublicIP)" - $IPConfig += $CurrentIPConfig - - if (-not (Test-Path -Path $IPConfigFilePath)) { - New-Item -Path $IPConfigFilePath -Force | Out-Null - } - - $IPConfig | ConvertTo-Json -AsArray | Set-Content -Path $IPConfigFilePath -Force - } -}