f12.hu
Open in
urlscan Pro
91.227.138.55
Public Scan
URL:
https://f12.hu/wp-content/uploads/2022/03/Check-NamedLocationIP-1.txt
Submission: On February 28 via manual from DK — Scanned from DK
Submission: On February 28 via manual from DK — Scanned from DK
Form analysis
0 forms found in the DOMText Content
$IPtoTest = Read-Host -Prompt "Enter IP to check" connect-azuread $namedLocations = Get-AzureADMSNamedLocationPolicy $obj_NamedLocations = $namedLocations.Where({$_.ipranges.cidraddress -ne $null}) | % { [pscustomobject]@{ DisplayName = $_.displayname IPRanges = $_.ipranges.cidraddress IsTrusted = $_.isTrusted } } function Check-IPAddress ($IPAddress, $Range){ #src = https://github.com/omniomi/PSMailTools/blob/v0.2.0/src/Private/spf/IPInRange.ps1 # Split range into the address and the CIDR notation [String]$CIDRAddress = $Range.Split('/')[0] [int]$CIDRBits = $Range.Split('/')[1] # Address from range and the search address are converted to Int32 and the full mask is calculated from the CIDR notation. [int]$BaseAddress = [System.BitConverter]::ToInt32((([System.Net.IPAddress]::Parse($CIDRAddress)).GetAddressBytes()), 0) [int]$Address = [System.BitConverter]::ToInt32(([System.Net.IPAddress]::Parse($IPAddress).GetAddressBytes()), 0) [int]$Mask = [System.Net.IPAddress]::HostToNetworkOrder(-1 -shl ( 32 - $CIDRBits)) # Determine whether the address is in the range. if (($BaseAddress -band $Mask) -eq ($Address -band $Mask)) { $true } else { $false } } $searchresult = $obj_namedLocations | Where-Object {($_.ipranges | % {Check-IPAddress $IPtoTest -Range $_}) -eq $true} if (!($searchresult)){Write-Host -ForegroundColor Red "IP Address not a named location"}else{$searchresult}