{"id":3203,"date":"2020-11-18T18:07:06","date_gmt":"2020-11-18T17:07:06","guid":{"rendered":"https:\/\/www.mariotti.de\/?p=3203"},"modified":"2020-11-18T18:07:06","modified_gmt":"2020-11-18T17:07:06","slug":"powershell-ip-address-range-test","status":"publish","type":"post","link":"https:\/\/dev.mariotti.de\/?p=3203","title":{"rendered":"Powershell IP Address Range Test"},"content":{"rendered":"<p>Simples PowerShell Beispiel wie man pr\u00fcfen kann, ob eine bestimmte IP Adresse innerhalb einer bestimmten IP Range ist.<\/p>\n<pre><code class=\"language-powershell\"># Test if IP is within IP range\nFunction Test-IsIpAddressInRange {\nparam(\n        [string] $IpAddress,\n        [string] $IpRangeStart,\n        [string] $IpRangeEnd\n    )\n    $ip = [system.net.ipaddress]::Parse($ipAddress).GetAddressBytes()\n    [array]::Reverse($ip)\n    $ip = [system.BitConverter]::ToUInt32($ip, 0)\n    $start = [system.net.ipaddress]::Parse($IpRangeStart).GetAddressBytes()\n    [array]::Reverse($start)\n    $start = [system.BitConverter]::ToUInt32($start, 0)\n    $end = [system.net.ipaddress]::Parse($IpRangeEnd).GetAddressBytes()\n    [array]::Reverse($end)\n    $end = [system.BitConverter]::ToUInt32($end, 0)\n    $Result = $start -le $ip -and $ip -le $end\n    Write-Host \"Test-IsIpAddressInRange -IpAddress $IpAddress -IpRangeStart $IpRangeStart -IpRangeEnd $IpRangeEnd\"\n    Return $Result\n}\n \n# Example to check all IPsTest if IP is within IP range\n\n# Get all local NICs with IPv4 address an check if within range 192.168.0.0-192.168.255.255\n$Nics = Get-NetAdapter | Get-NetIPConfiguration | Get-NetIPAddress | Where-Object {$_.AddressFamily -eq \"IPv4\"}\nforeach ($NIC in $NICs)\n{\n    Test-IsIpAddressInRange -IpAddress $NIC.IPAddress -IpRangeStart \"192.168.0.0\" -IpRangeEnd \"192.168.255.255\"\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Simples PowerShell Beispiel wie man pr\u00fcfen kann, ob eine bestimmte IP Adresse innerhalb einer bestimmten IP Range ist.<\/p>\n","protected":false},"author":2,"featured_media":2425,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"class_list":["post-3203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/posts\/3203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3203"}],"version-history":[{"count":0,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/posts\/3203\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/media\/2425"}],"wp:attachment":[{"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}