PowerShell traceroute with IP Geo information

Here is an example of using the free API service at ip-api.com with PowerShell

clear

# The destination IP or FQDN to trace route to:
$DST = "dns.google."

# What fields to get data for: 
$Fields = 66846719

# language (ISO 639) 
$Lang = "en"

# Run trace route
$Trace = Test-NetConnection $DST -TraceRoute

# Lookup ip information from IP-API.com for each hop:
$(ForEach ($IP in $Trace.TraceRoute){
    $Uri = "http://ip-api.com/json/$($IP)?fields=$($Fields)&lang=$($Lang)"
    Invoke-RestMethod -uri $Uri 
}) | Format-Table status,message,continent,continentCode,country,countryCode,region,regionName,city,district,zip,lat,lon,timezone,offset,currency,isp,org,as,asname,reverse,mobile,proxy,hosting,query -AutoSize

Posted

in

by