Created
February 11, 2013 14:29
-
-
Save jimfdavies/4754707 to your computer and use it in GitHub Desktop.
Get-GatewayFromIPAddress returns your IP gateway from your IP address. This assumes that your default gateway is on the same /24 subnet and its node address is .1 (configurable). Useful for automatic deployment scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-GatewayFromIPAddress { | |
param($ipaddress) | |
$routerip = ".1" | |
$gateway = (($ipaddress.Split("."))[0..2] -join ".") + $routerip | |
return $gateway | |
} | |
$ipaddress = "10.1.2.100" | |
$gateway = Get-GatewayFromIPAddress -ipaddress $ipaddress | |
$gateway # "10.1.2.1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment