-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-Routes
110 lines (98 loc) · 3.3 KB
/
New-Routes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function New-Routes {
param
(
[parameter(Mandatory=$true,
ValueFromPipeline=$false,
ValueFromPipelineByPropertyName=$false
)]
[int]$RouteQty=100,
[ValidateRange(1,32)]
[int]$minPref=24,
[ValidateRange(1,32)]
[int]$maxPref=30,
[ValidateSet("BGP","EIGRP","OSPF","NONE")]
[string]$Protocol="NONE"
)
process {
$addresses = @()
$i = $RouteQty
$Loopback = 1000
while ($i -ge 0) {
if ($minPref = $maxPref) { $PrefixLength = $maxPref } else {
$PrefixLength = Get-Random -Minimum $minPref -Maximum $maxPref
}
if ($Prefixlength -ge 32)
{
$m4 = 255
} else
{
$m4 = 256 - ([math]::Pow(2,((32 - $Prefixlength))))
}
if ($Prefixlength -ge 24)
{
$m3 = 255
} else
{
$m3 = 256 - ([math]::Pow(2,((24 - $Prefixlength))))
$m4 = 0
}
if ($Prefixlength -ge 16)
{
$m2 = 255
} else
{
$m2 = 256 - ([math]::Pow(2,((16 - $Prefixlength))))
$m3 = 0
$m4 = 0
}
if ($Prefixlength -ge 8)
{
$m1 = 255
} else
{
$m1 = 256 - ([math]::Pow(2,((8 - $Prefixlength))))
$m2 = 0
$m3 = 0
$m4 = 0
}
[Net.IPAddress]$prefSubnetMask="$m1.$m2.$m3.$m4"
$Oct1 = Get-Random -Minimum 1 -Maximum 223
$0ct2 = Get-Random -Minimum 0 -Maximum 255
$0ct3 = Get-Random -Minimum 0 -Maximum 255
$0ct4 = Get-Random -Minimum 1 -Maximum 254
[Net.IPAddress]$IPAddress="$Oct1.$0ct2.$0ct3.$0ct4"
$address = New-Object -TypeName PSObject
$address | Add-Member -MemberType NoteProperty -Name Addr -Value $IPAddress
$address | Add-Member -MemberType NoteProperty -Name Mask -Value $prefSubnetMask
$addresses += $address
"interface loopback $Loopback" | Out-File RouteConfig.txt -Append
" ip address $IPAddress $prefSubnetMask" | Out-File RouteConfig.txt -Append
"!" | Out-File RouteConfig.txt -Append
$Loopback++
$i--
}
if ($Protocol -eq "NONE") { $addresses | Out-File RouteConfig.txt -Append }
if ($Protocol -eq "BGP") {
"router bgp 999" | Out-File RouteConfig.txt -Append
$addresses | foreach {
$nw = $_.Addr
$nm = $_.Mask
" network $nw mask $nm " | Out-File RouteConfig.txt -Append
}
"end" | Out-File RouteConfig.txt -Append
"!" | Out-File RouteConfig.txt -Append
}
if ($Protocol -eq "OSPF") {
"router ospf 999" | Out-File RouteConfig.txt -Append
" network 0.0.0.0 area 0" | Out-File RouteConfig.txt -Append
"end" | Out-File RouteConfig.txt -Append
"!" | Out-File RouteConfig.txt -Append
}
if ($Protocol -eq "EIGRP") {
"router eigrp 999" | Out-File RouteConfig.txt -Append
" network 0.0.0.0" | Out-File RouteConfig.txt -Append
"end" | Out-File RouteConfig.txt -Append
"!" | Out-File RouteConfig.txt -Append
}
}
}