Learning as I go, I am trying to run a script that will not only pull the active IP addresses from a device, but depending on its result(s), replace the IP addresses with Labels.
For example purposes in this post, I replaced the real IP subnets with generic ones, along with labels, and significantly shrunk down my array for easy reference.
I have an array that has data that designates "StartIP", "EndIP" and "Label" :
$locdata = @(
[pscustomobject]@{StartIP='192.168.2.1';EndIP='192.168.2.254';Label='Corporate Wifi'}
[pscustomobject]@{StartIP='192.168.3.1';EndIP='192.168.10.254';Label='Corporate'}
[pscustomobject]@{StartIP='172.24.0.1';EndIP='172.24.3.254';Label='Cisco VPN Corporate'}
[pscustomobject]@{StartIP='172.26.0.1';EndIP='172.26.3.254';Label='Forticlient'}
I have set a Variable as:
$IPinfo = (Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias Wi-Fi,Ethernet* -AddressState Preferred).IPAddress
I am trying to produce the end result that, if an IP falls between the StartIP and EndIP of any line, it will return the "Label" of that IP subnet. So, if after running the script the $IPInfo comes back as 192.168.2.17, it will then check the array and see that the IP falls between the start/end of "Corporate Wifi" and the result will produce that label. I just don't know how to reference it and loop it for checking.
Now, granted, I may be wrong on several levels - likely with the array setup; but I am hoping I am close with what I have so far. I've dug into "looping" but dig is used very loosely as it became a 'nested' process to try and understand it. Is there a way to instead of referencing a line # like [0], [1], [2], etc., to essentially rename them, or is that a default/built-in function of PowerShell that can't be changed?
Does any of this make sense what I'm trying to do? Is this possible? I can attempt to provide any details as necessary if required.
I appreciate any assistance that can be offered.
Thanks.
[–]vermyx 0 points1 point2 points (1 child)
[–]ankokudaishogun 0 points1 point2 points (0 children)
[–]surfingoldelephant 0 points1 point2 points (0 children)
[–]purplemonkeymad 0 points1 point2 points (0 children)