<< Back to Script Library
Geolocate HDX session source IP
ControlUp can display the Source IP of the HDX Sessions connected to the NetScaler.
This is a sample script using the non-Commercial, anonymous service from ip-api.com. For the commercial service options, see https://members.ip-api.com/
Version: 2.14.24
Created: 2020-11-30
Modified: 2020-12-02
Creator: Marcel Calef
Downloads: 39
Tags: HDX netscaler ip geolocation
Created: 2020-11-30
Modified: 2020-12-02
Creator: Marcel Calef
Downloads: 39
Tags: HDX netscaler ip geolocation
<#
.SYNOPSIS HDX Session geolocate - IP-API sample
.DESCRIPTION ControlUp can display the Source IP of the HDX Sessions connected to the NetScaler.
Sample script action to use ip-api to obtain the geolocation.
Sample for non-Commercial use. For more info see https://members.ip-api.com/
.CONTEXT HDX Sessions
.TAGS $HDX
.HISTORY Marcel Calef - 2020-11-30 - initial Sample
#>
[CmdLetBinding()]
Param (
[Parameter(Mandatory=$true,HelpMessage='Source IP')] [string]$sourceIP,
[Parameter(Mandatory=$true,HelpMessage='Show or hide IP')] [string]$showIP,
[Parameter(Mandatory=$true,HelpMessage='Country, name or code')] [string]$country,
[Parameter(Mandatory=$true,HelpMessage='Region, name or code')] [string]$region,
[Parameter(Mandatory=$true,HelpMessage='Show or hide city')] [string]$city,
[Parameter(Mandatory=$true,HelpMessage='Show or hide ISP')] [string]$isp,
[Parameter(Mandatory=$true,HelpMessage='Show or hide coordinates')] [string]$coords,
[Parameter(Mandatory=$true,HelpMessage='Show or hide AS Name')] [string]$asname
)
Set-StrictMode -Version Latest
#$ErrorActionPreference = "continue"
#$VerbosePreference = "continue" ## comment this line to disable verbose debug output
Write-Verbose "Variables:"
Write-Verbose " sourceIP : $sourceIP"
Write-Verbose " showIP : $showIP"
Write-Verbose " country : $country"
Write-Verbose " region : $region"
Write-Verbose " city : $city"
Write-Verbose " isp : $isp"
Write-Verbose " coords : $coords"
Write-Verbose " asname : $asname"
$url = "http://ip-api.com/json/$sourceIP"
try {$geolocationSample = (Invoke-RestMethod -Method Get -Uri $url)}
catch { $_.Exception.Response.Headers.ToString();
Write-Host "Query failed. Have you exceeded the 45 per minute limit on the non-commercial service?
Please look into the commerical plans offered by https://ip-api.com"
exit
}
$status = " Status :" + $geolocationSample.status + " "
$output = "Geolocation : "
if ($showIP -like 'show') { $output += $($geolocationSample.query)+" " }
if ($country -like 'code') { $output += $($geolocationSample.countryCode) + "/" } else {$output += $($geolocationSample.country) + "/"}
if ($region -like 'code') { $output += $($geolocationSample.region) + ", " } else {$output += $($geolocationSample.regionName) + ", "}
if ($city -like 'show') { $output += $($geolocationSample.city) + ", " }
if ($isp -like 'show') { $output += $($geolocationSample.isp) + ", " }
if ($coords -like 'show') { $output += "$($geolocationSample.lat),$($geolocationSample.lon) | " }
if ($asname -like 'show') { $output += $($geolocationSample.as) }
# non Commercial sample script Disclamer text
$Disclaimer = " Sample script using the non-Commercial, anonymous service from ip-api.com. `
For the commercial serivce options, see https://members.ip-api.com/
"
# Print the Disclaimer, status and output
$Disclaimer
$status
$output