-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathGet-Geo.ps1
54 lines (47 loc) · 1.63 KB
/
Get-Geo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
$PublicIP_URI = 'http://ifconfig.me/ip'
$GEO_URI = 'http://ipinfo.io/'
Write-Host "--------------Testing GEO URL's--------------" -ForegroundColor Cyan
Write-Host "` "
function TestURL($URL) {
$URL_Mod = $URL.split("//")
$URL_ToTest = $URL_Mod[0] + '//' + $URL_Mod[2]
Try {
$Request = [System.Net.WebRequest]::Create($URL_ToTest)
$Response = $Request.getResponse()
If ($Response.StatusCode -eq 'OK') {
Write-Host "$URL_ToTest is accessible." -ForegroundColor green
$Return_Response = "OK"
}
Else {
Write-Warning "$URL_ToTest is not accessible. Site may be down."
$Return_Response = "Failed"
}
}
Catch {
Write-Warning "$URL_ToTest is not accessible. Site may be down."
$Return_Response = "Failed"
}
Return $Return_Response
}
If (((TestURL $PublicIP_URI) -eq "OK") -and ((TestURL $GEO_URI) -eq "OK")) {
$MY_GEO = Invoke-RestMethod -Uri ($GEO_URI + (Invoke-WebRequest -uri $PublicIP_URI).Content)
$MY_IP = $MY_GEO.ip
$MY_City = $MY_GEO.city
$MY_Region = $MY_GEO.region
$MY_Country = $MY_GEO.country
$MY_LOC = $MY_GEO.loc
$MY_ISP = $MY_GEO.org
Write-Host "` "
Write-Host "--------------Geolocation information--------------" -ForegroundColor Cyan
Write-Host "` "
Write-Output "IP Address: $MY_IP"
Write-Output "City: $MY_City"
Write-Output "Region: $MY_Region"
Write-Output "Country: $MY_Country"
Write-Output "Coordinates: $MY_LOC"
Write-Output "ISP: $MY_ISP"
Write-Host "` "
}
else {
Write-Warning "Could not obtain GEO information. URL(s) inaccessible."
}