diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..96c2e0d --- /dev/null +++ b/.gitattributes @@ -0,0 +1,15 @@ +# Needed for publishing of examples, build worker defaults to core.autocrlf=input. +* text eol=autocrlf + +*.mof text eol=crlf +*.sh text eol=lf +*.svg eol=lf + +# Ensure any exe files are treated as binary +*.exe binary +*.jpg binary +*.xl* binary +*.pfx binary +*.png binary +*.dll binary +*.so binary diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..134e9b5 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,50 @@ +# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners +# Each line is a file pattern followed by one or more owners. + +# These owners will be the default owners for everything in +# the repo. Unless a later match takes precedence, +# @global-owner1 and @global-owner2 will be requested for +# review when someone opens a pull request. +* @PSModule/module-maintainers + +# Order is important; the last matching pattern takes the most +# precedence. When someone opens a pull request that only +# modifies JS files, only @js-owner and not the global +# owner(s) will be requested for a review. +# *.js @js-owner + +# You can also use email addresses if you prefer. They'll be +# used to look up users just like we do for commit author +# emails. +# *.go docs@example.com + +# Teams can be specified as code owners as well. Teams should +# be identified in the format @org/team-name. Teams must have +# explicit write access to the repository. In this example, +# the octocats team in the octo-org organization owns all .txt files. +# *.txt @octo-org/octocats + +# In this example, @doctocat owns any files in the build/logs +# directory at the root of the repository and any of its +# subdirectories. +# /build/logs/ @doctocat + +# The `docs/*` pattern will match files like +# `docs/getting-started.md` but not further nested files like +# `docs/build-app/troubleshooting.md`. +# docs/* docs@example.com + +# In this example, @octocat owns any file in an apps directory +# anywhere in your repository. +# apps/ @octocat + +# In this example, @doctocat owns any file in the `/docs` +# directory in the root of your repository and any of its +# subdirectories. +# /docs/ @doctocat + +# In this example, @octocat owns any file in the `/apps` +# directory in the root of your repository except for the `/apps/github` +# subdirectory, as its owners are left empty. +# /apps/ @octocat +# /apps/github diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b92544a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: github-actions # See documentation for possible values + directory: / # Location of package manifests + schedule: + interval: weekly + - package-ecosystem: nuget # See documentation for possible values + directory: / # Location of package manifests + schedule: + interval: weekly diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..35c6ae8 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,18 @@ +# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuring-automatically-generated-release-notes + +changelog: + exclude: + labels: + - NoRelease + categories: + - title: 🌟 Breaking Changes + labels: + - Major + - Breaking + - title: 🚀 New Features + labels: + - Minor + - Feature + - title: Other Changes + labels: + - '*' diff --git a/.github/workflows/Process-PSModule.yml b/.github/workflows/Process-PSModule.yml new file mode 100644 index 0000000..b14321b --- /dev/null +++ b/.github/workflows/Process-PSModule.yml @@ -0,0 +1,26 @@ +name: Process-PSModule + +run-name: "Process-PSModule - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" + +on: + pull_request: + branches: + - main + types: + - closed + - opened + - reopened + - synchronize + - labeled + +concurrency: + group: ${{ github.workflow }} + +permissions: + contents: write + pull-requests: write + +jobs: + Process-PSModule: + uses: PSModule/Process-PSModule/.github/workflows/workflow.yml@v1 + secrets: inherit diff --git a/.gitignore b/.gitignore index dfcfd56..907bfea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,350 +1,13 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore - -# User-specific files -*.rsuser -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUnit -*.VisualState.xml -TestResult.xml -nunit-*.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/* + +# The Powershell build outputs folder +outputs/* diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..038896b --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,6 @@ +{ + "recommendations": [ + "github.vscode-github-actions", + "ms-vscode.powershell" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e732ea1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,81 @@ +{ + "[json]": { + "editor.defaultFormatter": "vscode.json-language-features" + }, + "[jsonc]": { + "editor.defaultFormatter": "vscode.json-language-features" + }, + "[markdown]": { + "editor.defaultFormatter": "yzhang.markdown-all-in-one", + "editor.quickSuggestions": { + "comments": "off", + "other": "off", + "strings": "off" + }, + "editor.wordWrap": "off" + }, + "[powershell]": { + "editor.defaultFormatter": "ms-vscode.powershell", + "editor.wordSeparators": "`~!@#%^&*()=+[{]}\\|;:'\",.<>/?", + "files.encoding": "utf8bom" + }, + "[yaml]": { + "editor.defaultFormatter": "github.vscode-github-actions", + "editor.insertSpaces": true, + "editor.tabSize": 2, + }, + "[github-actions-workflow]": { + "editor.defaultFormatter": "github.vscode-github-actions", + "editor.insertSpaces": true, + "editor.tabSize": 2 + }, + "editor.rulers": [0, 150], + "powershell.codeFormatting.autoCorrectAliases": true, + "powershell.codeFormatting.newLineAfterCloseBrace": false, + "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationForFirstPipeline", + "powershell.codeFormatting.preset": "OTBS", + "powershell.codeFormatting.trimWhitespaceAroundPipe": true, + "powershell.codeFormatting.useConstantStrings": true, + "powershell.codeFormatting.useCorrectCasing": true, + "powershell.codeFormatting.whitespaceBetweenParameters": true, + "powershell.pester.codeLens": false, + "powershell.powerShellDefaultVersion": "PowerShell (x64)", + "powershell.scriptAnalysis.enable": true, + "todo-tree.general.tags": [ + "BUG", + "HACK", + "FIXME", + "TODO", + "DEBUG" + ], + "todo-tree.highlights.customHighlight": { + "TODO": { + "background": "#00ff00", + "foreground": "#ffffff", + "icon": "alert", + "iconColour": "#00ff00", + "type": "text-and-comment" + }, + "HACK": { + "background": "#ff0000", + "foreground": "#ffffff", + "icon": "alert", + "iconColour": "#ff0000", + "type": "text-and-comment" + }, + "FIXME": { + "background": "#ff0000", + "foreground": "#ffffff", + "icon": "alert", + "iconColour": "#ff0000", + "type": "text-and-comment" + }, + "BUG": { + "background": "#ff0000", + "foreground": "#ffffff", + "icon": "alert", + "iconColour": "#ff0000", + "type": "text-and-comment" + } + } +} diff --git a/LICENSE b/LICENSE index 3e7c40e..92f4384 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 Marius Storhaug +Copyright (c) 2024 PSModule Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2e1e298..e1c740e 100644 --- a/README.md +++ b/README.md @@ -1 +1,52 @@ -# PublicIP \ No newline at end of file +# Fonts + +This is a PowerShell module for getting information about your public IP. +It uses the APIs of [IPInfo](https://ipinfo.io) and [MyIP](https://www.myip.com/) to get this data. + +## Prerequisites + +This module requires an internet connection to work. + +## Installation + +To install the module simply run the following command in a PowerShell terminal. + +```powershell +Install-PSResource -Name PublicIP +Import-Module -Name PublicIP +``` + +## Usage + +You can use this module to get info about your public IP. + +### List information about your public IP and ISP + +This command will information about your public IP and more information about your ISP. + +```powershell +Get-PublicIP +``` + +### List public IP using 'MyIP' API + +This command will get your public IP using the 'MyIP' API. + +```powershell +Get-PublicIP -Provider MyIP +``` + +## Contributing + +Coder or not, you can contribute to the project! We welcome all contributions. + +### For Users + +If you don't code, you still sit on valuable information that can make this project even better. If you experience that the +product does unexpected things, throw errors or is missing functionality, you can help by submitting bugs and feature requests. +Please see the issues tab on this project and submit a new issue that matches your needs. + +### For Developers + +If you do code, we'd love to have your contributions. Please read the [Contribution guidelines](CONTRIBUTING.md) for more information. +You can either help by picking up an existing issue or submit a new one if you have an idea for a new feature or improvement. diff --git a/icon/icon.png b/icon/icon.png new file mode 100644 index 0000000..be83fd5 Binary files /dev/null and b/icon/icon.png differ diff --git a/src/PublicIP/PublicIP.psd1 b/src/PublicIP/PublicIP.psd1 new file mode 100644 index 0000000..aab729f --- /dev/null +++ b/src/PublicIP/PublicIP.psd1 @@ -0,0 +1,20 @@ +@{ + ModuleVersion = '0.0.1' + Description = 'PowerShell Module for Public IP' + HelpInfoURI = 'https://PSModule.github.io/PublicIP' + PrivateData = @{ + PSData = @{ + Tags = @( + 'PublicIP' + 'IP' + 'Public' + 'IPConfig' + 'Config' + ) + LicenseUri = 'https://github.com/PSModule/PublicIP/blob/main/LICENSE' + ProjectUri = 'https://github.com/PSModule/PublicIP' + IconUri = 'https://raw.githubusercontent.com/PSModule/PublicIP/main/icon/icon.png' + } + } +} + diff --git a/src/PublicIP/PublicIP.psm1 b/src/PublicIP/PublicIP.psm1 new file mode 100644 index 0000000..573c80d --- /dev/null +++ b/src/PublicIP/PublicIP.psm1 @@ -0,0 +1,32 @@ +[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" + } + } +} + +$Param = @{ + Function = (Get-ChildItem -Path "$PSScriptRoot\public" -Include '*.ps1' -Recurse).BaseName + Variable = '*' + Cmdlet = '*' + Alias = '*' +} + +Write-Verbose 'Exporting module members' + +Export-ModuleMember @Param -Verbose diff --git a/src/PublicIP/private/common.ps1 b/src/PublicIP/private/common.ps1 new file mode 100644 index 0000000..a58fa50 --- /dev/null +++ b/src/PublicIP/private/common.ps1 @@ -0,0 +1,4 @@ +$script:providerMap = @{ + MyIP = 'https://api.myip.com/' + IPInfo = 'https://ipinfo.io/json' +} diff --git a/src/PublicIP/public/Get-PublicIP.ps1 b/src/PublicIP/public/Get-PublicIP.ps1 new file mode 100644 index 0000000..9d0b6b7 --- /dev/null +++ b/src/PublicIP/public/Get-PublicIP.ps1 @@ -0,0 +1,23 @@ +function Get-PublicIP { + <# + .SYNOPSIS + Gets your public IP address. + + .DESCRIPTION + Gets your public IP address. You can specify a provider to use by using the Provider parameter. + + .EXAMPLE + Get-PublicIP + + .EXAMPLE + Get-PublicIP -Provider MyIP + #> + param( + # The provider to use to get the public IP address. + [Parameter()] + [ValidateScript({ $providerMap.Keys })] + $Provider = 'IPInfo' + ) + + Invoke-RestMethod -Uri $providerMap[$Provider] +}