Wednesday, March 16, 2011

First to convert this to a #Powershell one-liner wins a high five



# Take an IP address as a string, increment the last octet by one and return the string

$array = ("192.168.1.1").split(".")

[int]$array[3] = ([int]$array[3]) + 1

$IP = $array -join "."

# Can it be done?

1 comment:

  1. Sure:

    [Regex]::Replace('192.168.1.255', '\d{1,3}$', {[Int]$args[0].Value + 1})

    ReplyDelete