Skip to content

Commit 038b957

Browse files
authored
feat: add function to get public IP address (#12)
* Add function to get public IP address Fixes #11
1 parent 4c2751a commit 038b957

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

PSF.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
# NestedModules = @()
7070

7171
# 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.
72-
FunctionsToExport = @('Get-oAuthToken', 'Get-RandomPassword', 'Get-WiFiKnownPasswords')
72+
FunctionsToExport = @('Get-oAuthToken', 'Get-RandomPassword', 'Get-WiFiKnownPasswords', 'Get-PublicIP')
7373

7474
# 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.
7575
CmdletsToExport = @()
@@ -78,7 +78,7 @@
7878
# VariablesToExport = @()
7979

8080
# 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.
81-
AliasesToExport = @('gpw')
81+
AliasesToExport = @('gpw', 'gpip', 'Get-PublicIPAddress')
8282

8383
# DSC resources to export from this module
8484
# DscResourcesToExport = @()

PSF.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
. $PSScriptRoot\functions\Get-oAuthToken.ps1
44
. $PSScriptRoot\functions\Get-RandomPassword.ps1
55
. $PSScriptRoot\functions\Get-WiFiKnownPasswords.ps1
6+
. $PSScriptRoot\functions\Get-PublicIP.ps1

functions/Get-PublicIP.ps1

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function Get-PublicIP {
2+
<#
3+
.SYNOPSIS
4+
Returns the public IP address for the connected network.
5+
.DESCRIPTION
6+
Uses the ipify.org API to lookup the Public IP address.
7+
The function will return the Public IP as well as copy it to your clipboard.
8+
.EXAMPLE
9+
C:\PS> Get-PublicIP
10+
Returns the current IPv4 Public IP for the connected network.
11+
.EXAMPLE
12+
C:\PS> Get-PublicIP -v6
13+
Returns the current IPv6 (if available) Public IP for the connected network.
14+
.OUTPUTS
15+
Public IP address(es)
16+
.NOTES
17+
Version 1.0.0
18+
#>
19+
[CmdletBinding()]
20+
param (
21+
# IPv6 switch
22+
[Parameter(Mandatory = $false, HelpMessage = 'Perform an IPv6 lookup')]
23+
[switch] $v6
24+
)
25+
26+
begin {
27+
$ErrorActionPreference = 'Stop'
28+
$Uri = 'https://api.ipify.org?format=json'
29+
if ($6) {
30+
$Uri = 'https://api64.ipify.org?format=json'
31+
}
32+
}
33+
34+
process {
35+
$resp = (Invoke-WebRequest $Uri -ErrorAction 'stop').Content | ConvertFrom-Json
36+
}
37+
38+
end {
39+
$resp.ip | clip
40+
return $resp.ip
41+
}
42+
}
43+
44+
New-Alias -Name gpip -Value Get-PublicIP
45+
New-Alias -Name Get-PublicIPAddress -Value Get-PublicIP

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy