forked from Am0rphous/Create-WiFi-Hotspot-PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManage-and-create-WiFi-HotSpot.ps1
244 lines (176 loc) · 8.78 KB
/
Manage-and-create-WiFi-HotSpot.ps1
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<#
Commands are found and explained at: technet.microsoft.com/en-us/library/cc755301(v=ws.10).aspx
Author: Henrik Johnsen
Github: github.com/Am0rphous
Purpose: Help manage and create wireless networks on Windwos based computers
A donation is highly appreciated.
- Bitcoin address : 1Eib5FGoWBZv6Pc17LiduLXkf8KEC1DQVc
- Litecoin address : Lg2W5qBfaKGshz3w6m7JQ9EHmTsG6haBmW
#>
function CatchErrorMessage {
# `n gives a new line
# `t makes a tabulator space
# $_ shows the error message
# 'Fore' is short for 'ForegroundColor'
Write-Host "`t$_`n" -Fore Red
}
Function Prompt_reload_menu {
Read-Host "`tPress 'enter'to go back"
$menuOption = 0
LoadMenu #Calls for the function
}
Function Reload_menu_now {
$menuOption = 0
LoadMenu #Calls for the function
}
Function LoadMenu {
[int] $menuOption = 0 #Resets the menuoptions for each time the menu loads
$t = "`t`t" #Each 't' makes a tab space from the left
$nt = "`n`t`t" #Makes a new line and two tabulator spaces
[int] $LastOption = 10 #Total number of options in the menu
[string] $MenuBar = "`n=========== Wifi HotSpot with PowerShell - Version 1.0 ==========="
#Foreach option in the menu, the script checks if the user has chosen
#a value less than 1 or an option greater than the last menu option.
#If the value is outside of the menu options, the code in 'default' will
#excecute.
while ( $menuOption -lt 1 -or $menuOption -gt $LastOption ) {
CLS #Clears the creen
Write-Host $MenuBar -Fore Magenta
Write-Host "`n`tgithub.com/Am0rphous"
Write-Host "$nt`Choose between these options:" -Fore Cyan
Write-host "$nt`1. " -NoNewline -Fore Cyan; Write-Host "Configure a Wifi HotSpot"
Write-host "$nt`2. " -NoNewline -Fore Cyan; Write-Host "Start Wifi HotSpot"
Write-host "$nt`3. " -NoNewline -Fore Cyan; Write-Host "Stop Wifi HotSpot"
Write-host "$nt`4. " -NoNewline -Fore Cyan; Write-Host "View hosted network settings"
Write-host "$nt`5. " -NoNewline -Fore Cyan; Write-Host "Show Wireless LAN settings"
Write-host "$nt`6. " -NoNewline -Fore Cyan; Write-Host "Display blocked networks"
Write-host "$nt`7. " -NoNewline -Fore Cyan; Write-Host "Show info about interfaces"
Write-host "$nt`8. " -NoNewline -Fore Cyan; Write-Host "Display all information"
Write-host "$t - Displays the entire collection of information about wireless
network adapters, wireless profiles and wireless networks"
Write-host "$nt`9. " -NoNewline -Fore Cyan; Write-Host "Show available drivers"
Write-host "$nt`10. " -NoNewline -Fore Cyan; Write-Host "Exit"
#Gets input which is supposed to an integer value from the user
[Int] $menuOption = Read-Host "`n`tOption"
if ( $menuOption -lt 1 -or $menuOption -gt $LastOption ) {
Write-Host "$nt`Please choose a number in the menu" -Fore Red
Sleep -Seconds 2 #Script pauses for two seconds, so the user has time to read the error message
}
Write-Host "" #Shows the feedback to the user one line further down
}
Switch ( $menuOption ) {
1 { #Option 1 - Configure Wifi HotSpot
#First - Specify a network name
Do {
Write-Host "`tPlease specify SSID (name) of network:" -Fore Cyan
[string] $SSID = Read-Host "`n`tSSID"
if ($SSID -eq "") { Write-Host "`n`tThe name can't be empty!" -Fore Red }
} while ($SSID -eq "")
#Second - Specify a password for network
Do {
Write-Host "`n`tPlease specify a password for network." -Fore Cyan
Write-Host "`tPassword must contain at least eight characters." -Fore Cyan
[string] $password = Read-Host "`n`tPassword"
if ($password -eq "") { Write-Host "`n`tThe field can't be empty!" -Fore Red }
if ($password.Length -lt 8) { Write-Host "`n`tThe password can't be less than eight characters!" -Fore Red }
} while ($password -eq "" -or $password.Length -lt 8)
#Third - Create the network with specified settings
Try {
Write-Host ""
netsh wlan set hostednetwork mode=allow ssid=$SSID key=$password
#Following code checks if the previous code executed sucessfully and gives
#feedback to the user
If ($?) { Write-Host "`n`tCreated Wifi Hotspot '$SSID' sucessfully" -Fore Green }
} Catch { #If something goes wrong a error message will be displayed
Write-Host "`n`tSomething went wrong while creating the hotspot '$SSID'" -Fore Yellow
CatchErrorMessage
}
#Fourth - Start the network now?
Do {
Write-Host "`n`tDo you wish to start the new network now? 'Y' for 'yes' and 'N' for 'no'" -Fore Cyan
[string] $Answer = Read-Host "`n`tY/N"
if ($Answer -eq "" -or
$Answer -ne "y" -and
$Answer -ne "n"
) { Write-Host "`n`tPlease enter 'y' for 'yes' or 'n' for 'no'" -Fore Red }
} while ($Answer -ne "y" -and $Answer -ne "n")
#Checks if the user answered 'n' for 'no' to starting the network right away
If ($Answer -eq "n") {
Reload_menu_now
}
else { #if user didn't answer 'n' then he/she wishes then to start the network
Try {
Write-Host ""
netsh wlan start hostednetwork
Prompt_reload_menu
} Catch { CatchErrorMessage }
}
} #Option 1 - Configure Wifi HotSpot
2 { #Option 2 - Start Wifi HotSpot
Try { netsh wlan start hostednetwork }
Catch { CatchErrorMessage }
Prompt_reload_menu
} #Option 2 - Start Wifi HotSpot
3 { #Option 3 - Stop Wifi HotSpot
Try { netsh wlan stop hostednetwork }
Catch { CatchErrorMessage }
Prompt_reload_menu
} #Option 3 - Stop Wifi HotSpot
4 { #Option 4 - View hosted network settings
Try { netsh wlan show hostednetwork }
Catch { CatchErrorMessage }
Prompt_reload_menu
} #Option 4 - View hosted network settings
5 { #Option 5 - Show Wireless LAN settings
Try {
netsh wlan show settings #Displays settings
Prompt_reload_menu
}
Catch { CatchErrorMessage }
} #Option 5 - Show Wireless LAN settings
6 { #Option 6 - display blocked networks
Try { netsh wlan show blockednetworks }
Catch { CatchErrorMessage }
Prompt_reload_menu
} #Option 6 - display blocked networks
7 { #Option 7 - Show info about interfaces
Try { netsh wlan show interfaces }
Catch { CatchErrorMessage }
Prompt_reload_menu
} #Option 7 - Show info about interfaces
8 { #Option 8 - Show info about interfaces
Try { netsh wlan show all }
Catch { CatchErrorMessage }
Prompt_reload_menu
} #Option 8 - Show info about interfaces
9 { #Option 9 - Show available drivers
Try {
$Drivers = netsh wlan show drivers
if ($Drivers) {
Write-Host "`tFound folowing drivers" -Fore Green
$Drivers
Write-Host "`tMake sure to check if the drivers support hosting a network`n" -Fore Yellow
}
else { Write-Host "`tCouldn't find any drivers" -Fore Red }
} Catch { CatchErrorMessage }
#Prompts the user to push 'enter' to go back to main menu
Prompt_reload_menu
} #Option 9 - Show available drivers
default { #Code to execute if option number 10 is chosen
Write-Host "`t __________________ "
Write-Host "`t< Good bye >"
Write-Host "`t ------------------"
Write-Host "`t \ ^__^"
Write-Host "`t \ (oo)\_______"
Write-Host "`t (__)\ )\/\"
Write-Host "`t ||----w |"
Write-Host "`t__v_v___v_____v_" -Fore Green -NoNewline
Write-Host "||" -NoNewline
Write-Host "_____" -Fore Green -NoNewline
Write-Host "||" -NoNewline
Write-Host "__`n" -Fore Green
exit #Exits script
} #Code to execute if option number 10 is chosen
}#End switch
}#End function
LoadMenu #Calls for the menu