-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0b690a
commit c6440f8
Showing
11 changed files
with
130 additions
and
287 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,35 @@ | ||
# | ||
# Module manifest for module 'PublicIP' | ||
# | ||
# Generated by: Marius Storhaug | ||
# | ||
# Generated on: 16.12.2021 | ||
# | ||
|
||
@{ | ||
|
||
# Script module or binary module file associated with this manifest. | ||
RootModule = 'PublicIP.psm1' | ||
|
||
# Version number of this module. | ||
ModuleVersion = '0.0.1' | ||
|
||
# Supported PSEditions | ||
CompatiblePSEditions = @('Core') | ||
|
||
# ID used to uniquely identify this module | ||
GUID = 'dcbfe52d-b875-4f8b-ac39-0f958f57f9ae' | ||
|
||
# Author of this module | ||
Author = 'Marius Storhaug' | ||
Author = 'Marius Storhaug' | ||
|
||
# Company or vendor of this module | ||
CompanyName = 'Marius Storhaug' | ||
|
||
# Copyright statement for this module | ||
Copyright = '(c) Marius Storhaug. All rights reserved.' | ||
CompanyName = 'Marius Storhaug' | ||
|
||
# Description of the functionality provided by this module | ||
Description = 'PowerShell Module for Public IP' | ||
|
||
# Minimum version of the PowerShell engine required by this module | ||
PowerShellVersion = '7.0' | ||
|
||
# Name of the PowerShell host required by this module | ||
# PowerShellHostName = '' | ||
|
||
# Minimum version of the PowerShell host required by this module | ||
# PowerShellHostVersion = '' | ||
|
||
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. | ||
# DotNetFrameworkVersion = '' | ||
|
||
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. | ||
# ClrVersion = '' | ||
|
||
# Processor architecture (None, X86, Amd64) required by this module | ||
# ProcessorArchitecture = '' | ||
|
||
# Modules that must be imported into the global environment prior to importing this module | ||
# RequiredModules = @() | ||
|
||
# Assemblies that must be loaded prior to importing this module | ||
# RequiredAssemblies = @() | ||
|
||
# Script files (.ps1) that are run in the caller's environment prior to importing this module. | ||
# ScriptsToProcess = @() | ||
|
||
# Type files (.ps1xml) to be loaded when importing this module | ||
# TypesToProcess = @() | ||
|
||
# Format files (.ps1xml) to be loaded when importing this module | ||
# FormatsToProcess = @() | ||
|
||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess | ||
# NestedModules = @() | ||
|
||
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. | ||
FunctionsToExport = '*' | ||
|
||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. | ||
CmdletsToExport = '*' | ||
|
||
# Variables to export from this module | ||
VariablesToExport = '*' | ||
|
||
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. | ||
AliasesToExport = '*' | ||
|
||
# DSC resources to export from this module | ||
# DscResourcesToExport = @() | ||
|
||
# List of all modules packaged with this module | ||
# ModuleList = @() | ||
|
||
# List of all files packaged with this module | ||
# FileList = @() | ||
Description = 'PowerShell Module for Public IP' | ||
|
||
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. | ||
PrivateData = @{ | ||
PrivateData = @{ | ||
|
||
PSData = @{ | ||
|
||
# Tags applied to this module. These help with module discovery in online galleries. | ||
Tags = @('PublicIP', 'IP', 'Public', 'IPConfig', 'Config') | ||
Tags = @('PublicIP', 'IP', 'Public', 'IPConfig', 'Config') | ||
|
||
# A URL to the license for this module. | ||
LicenseUri = 'https://github.com/MariusStorhaug/PublicIP/blob/main/LICENSE' | ||
LicenseUri = 'https://github.com/MariusStorhaug/PublicIP/blob/main/LICENSE' | ||
|
||
# A URL to the main website for this project. | ||
ProjectUri = 'https://github.com/MariusStorhaug/PublicIP' | ||
ProjectUri = 'https://github.com/MariusStorhaug/PublicIP' | ||
|
||
# A URL to an icon representing this module. | ||
IconUri = 'https://raw.githubusercontent.com/MariusStorhaug/PublicIP/main/icon/PowerShell_Core_6.0_icon.png' | ||
|
||
# ReleaseNotes of this module | ||
# ReleaseNotes = '' | ||
|
||
# Prerelease string of this module | ||
# Prerelease = '' | ||
|
||
# Flag to indicate whether the module requires explicit user acceptance for install/update/save | ||
RequireLicenseAcceptance = $false | ||
|
||
# External dependent modules of this module | ||
# ExternalModuleDependencies = @() | ||
IconUri = 'https://raw.githubusercontent.com/MariusStorhaug/PublicIP/main/icon/PowerShell_Core_6.0_icon.png' | ||
|
||
} # End of PSData hashtable | ||
|
||
} # End of PrivateData hashtable | ||
|
||
# HelpInfo URI of this module | ||
HelpInfoURI = 'https://mariusstorhaug.github.io/PublicIP' | ||
|
||
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. | ||
# DefaultCommandPrefix = '' | ||
HelpInfoURI = 'https://mariusstorhaug.github.io/PublicIP' | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,32 @@ | ||
$script:providerMap = @{ | ||
MyIP = 'https://api.myip.com/' | ||
IPInfo = 'https://ipinfo.io/json' | ||
} | ||
|
||
Function Get-PublicIP { | ||
param( | ||
[Parameter(Mandatory = $false)] | ||
[ValidateScript({$providerMap.Keys})] | ||
$Provider = 'IPInfo' | ||
) | ||
|
||
Invoke-RestMethod -Uri $providerMap[$Provider] | ||
} | ||
|
||
Function 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 | ||
} | ||
|
||
$IPConfigFilePath = "$([Environment]::GetFolderPath('MyDocuments'))\IPConfig.json" | ||
|
||
Function 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 | ||
[Cmdletbinding()] | ||
param() | ||
|
||
Write-Verbose 'Importing subcomponents' | ||
$Folders = 'classes', 'private', 'public' | ||
# Import everything in these folders | ||
Foreach ($Folder in $Folders) { | ||
$Root = Join-Path -Path $PSScriptRoot -ChildPath $Folder | ||
Write-Verbose "Processing folder: $Root" | ||
if (Test-Path -Path $Root) { | ||
Write-Verbose "Getting all files in $Root" | ||
$Files = $null | ||
$Files = Get-ChildItem -Path $Root -Include '*.ps1', '*.psm1' -Recurse | ||
# dot source each file | ||
foreach ($File in $Files) { | ||
Write-Verbose "Importing $($File)" | ||
Import-Module $File | ||
Write-Verbose "Importing $($File): Done" | ||
} | ||
|
||
$IPConfig | ConvertTo-Json -AsArray | Set-Content -Path $IPConfigFilePath -Force | ||
} | ||
} | ||
|
||
Function Restore-IPConfig { | ||
if (Test-Path -Path $IPConfigFilePath) { | ||
return Get-Content -Path $IPConfigFilePath | ConvertFrom-Json | ||
} | ||
$Param = @{ | ||
Function = (Get-ChildItem -Path "$PSScriptRoot\public" -Include '*.ps1' -Recurse).BaseName | ||
Variable = '*' | ||
Cmdlet = '*' | ||
Alias = '*' | ||
} | ||
|
||
Function 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 | ||
} | ||
Write-Verbose 'Exporting module members' | ||
|
||
Export-ModuleMember -Function '*' -Alias '*' -Variable '*' -Cmdlet '*' | ||
Export-ModuleMember @Param -Verbose |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
$script:providerMap = @{ | ||
MyIP = 'https://api.myip.com/' | ||
IPInfo = 'https://ipinfo.io/json' | ||
} | ||
|
||
$script:IPConfigFilePath = "$([Environment]::GetFolderPath('MyDocuments'))\IPConfig.json" |
Oops, something went wrong.