Created
July 12, 2018 00:46
-
-
Save marckassay/1443c9ec28e2cf431de67cfb82f0bb52 to your computer and use it in GitHub Desktop.
Calls a REST endpoint to retrieve your IPv4 address along with other information on about ISP and geo-location
This file contains hidden or 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
<# | |
.SYNOPSIS | |
Calls a REST endpoint to retrieve your IPv4 address along with other information about ISP and geo-location | |
.DESCRIPTION | |
Long description | |
.PARAMETER Uri | |
The REST service providing the ISP information from your request. Defaults to 'http://ipinfo.io/json' | |
.EXAMPLE | |
E:\> Get-PublicIPv4Log | |
START | |
Wednesday, July 11, 2018 8:28:17 PM | |
{ | |
"ip": "23.121.76.104", | |
"hostname": "23-121-76-104.lightspeed.dybhfl.sbcglobal.net", | |
"city": "Orlando", | |
"region": "Florida", | |
"country": "US", | |
"loc": "28.53953,-81.30167", | |
"postal": "32806", | |
"org": "AS7018 AT&T Services, Inc." | |
} | |
END | |
E:\> | |
.EXAMPLE | |
E:\> Get-PublicIPv4Log | Add-Content -Path 'C:\Users\Marc\Desktop\IPv4Log.txt' | |
E:\> | |
.LINK | |
.NOTES | |
General notes | |
#> | |
function Get-PublicIPv4Log { | |
[CmdletBinding()] | |
Param | |
( | |
[Parameter(Mandatory = $false, Position = 1)] | |
[ValidateNotNullOrEmpty()] | |
[uri]$Uri = 'http://ipinfo.io/json' | |
) | |
$Datetime = Get-Date | Select-Object -ExpandProperty Datetime | |
$IpInfo = Invoke-RestMethod -Uri $Uri| ConvertTo-Json | |
Out-String -InputObject @" | |
START | |
$DateTime | |
$IpInfo | |
END | |
"@ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment