search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
How to parse CIDR on Powershell
Posted in Windows Powershell, Windows Server | No Comment | 8,032 views | 10/04/2009 19:25

You can parse CIDR on Powershell with this script:

1
2
3
4
5
6
7
8
9
10
11
12
13
$IPAddress = “192.168.1.1/24$address = ($IpAddress.split("/")[0])
$cidr = ([int]($IpAddress.split("/")[1]))
$netid = [System.Net.IPAddress]("$address");
$bits = $netid.GetAddressBytes()
$ip1=$bits[0]
$ip2=$bits[1]
$ip3=$bits[2]
$ip4=$bits[3]+1
$Gateway = $address
$IPAddress1 = "$ip1.$ip2.$ip3.$ip4"
write-Output $Gateway
write-Output $IPAddress1

You can use if/else statement for $cidr.



Leave a Reply