Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Regex not filtering private IP ranges

$
0
0

I’m trying to pull public IP’s hardcoded to NICs using Get- NetIPAddress. I’m trying to filter out any private IP address ranges to pull only public IP ranges. Trying to do this with a quick one liner.

$regex = "/(^127.)|(^192.168.)|(^10.)|(^172.1[6-9].)|(^172.2[0-9].)|(^172.3[0-1].)|(^::1$)|(^[fF][cCdD])/" $publicIP = (Get-NetIPAddress -AddressFamily IPv4) | where {$_.IPAddress -notcontains $regex} 

I’m missing something simple. Any ideas where? I’ve tried using -notlike, -notequals, etc. to no avail.

submitted by /u/a_spicy_memeball
[link] [comments]

The post Regex not filtering private IP ranges appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Latest Images

Trending Articles



Latest Images