October 29, 2015 at 1:37 pm #31499
I need some help on reordering my string value for ReverseDNS.
Currently String: 184.108.40.206
I want it to be: 10.24.20.75
I tried use regex to switch the string in reverse but it does all the values:
October 29, 2015 at 1:51 pm #31500
split and then reassemble in reverse
$IPOctects = "220.127.116.11" -split "\." $IP = "$($IPOctects).$($IPOctects).$($IPOctects).$($IPOctects)" $IP 10.24.20.75
October 29, 2015 at 1:56 pm #31501
Thanks Curtis, that's exactly what I was trying to accomplish
October 29, 2015 at 1:58 pm #31502
Or split into an array, reverse the array, and join string again
PS C:\> $String = '18.104.22.168' PS C:\> $String 22.214.171.124 PS C:\> $Array = $String.Split('.') PS C:\> [array]::Reverse($Array) PS C:\> $Reversed = $Array -join '.' PS C:\> $Reversed 10.24.20.75
October 29, 2015 at 2:01 pm #31503
$IP = "126.96.36.199".split(".") [array]::Reverse($IP) $IP -join "." 10.24.20.75
October 29, 2015 at 2:02 pm #31504
ah, bet me to the other option Christian 😀
October 29, 2015 at 2:17 pm #31505
Found another interesting regex way here:
$String = '188.8.131.52' (New-Object RegEx '[^\.]+', 'RightToLeft').Matches($String) -join '.'
October 29, 2015 at 2:19 pm #31506
I was actually going to suggest the reverse method also. However I got stuck for a couple of minutes due to the fact that the static reverse method does not return anything (void) and the signature does not suggest that is takes a [ref] variable ( static void Reverse(array array)). As it is a void, it should not return anything, however how does that work without [ref]?
October 29, 2015 at 2:21 pm #31507
Is there a way to have the input as a variable? Instead of a static entry of 184.108.40.206, the variable may contain more than one entry.
$IPs = '220.127.116.11','18.104.22.168'
October 29, 2015 at 2:44 pm #31510
but of course there is. Here is an advanced function that supports pipeline input as well:
You must be logged in to reply to this topic.