-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCreateNetwork.bat
More file actions
220 lines (172 loc) · 3.96 KB
/
CreateNetwork.bat
File metadata and controls
220 lines (172 loc) · 3.96 KB
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
@echo off
title Create Network
setlocal EnableExtensions EnableDelayedExpansion
:Arguments (
if /i [%1]==[/?] (
goto :ModeUse
)
if /i [%1]==[-start] (
call :startNetwork
exit
)
if /i [%1]==[-stop] (
call :stopNetwork
exit
)
if not defined [%1] goto :Init
call :stopNetwork
call :setNetwork %1 %2
call :startNetwork
exit
)
:Init (
call :getUserNetwork && cls
call :getPassNetwork "%network_name%"
call :stopNetwork
call :setNetwork "%network_name%" "%network_pass%"
call :startNetwork
echo.
echo 1) New Network, 2) Stop Network and Close
goto :Finished
)
::::::::::::::::::::::::::::
:: Network Data ::
::::::::::::::::::::::::::::
:getUserNetwork (
set /p network_name=Network Name:
if ["%network_name%"]==[""] (
cls && call :getUserNetwork
)
exit /b 0
)
:getPassNetwork (
call :PainText 0F "Network Name, "
call :PainText 02 " %~1"
echo.
call :getMaskingPassword user_password "Network Key: "
if ["%network_pass%"]==[""] (
cls && call :getPassNetwork "%~1"
) else (
call :getSizeString "%network_pass%"
)
if %CountString% LSS 8 (
call :PainText 04 "Enter a password with at least 8 digits"
timeout /t 10
cls && call :getPassNetwork "%~1"
)
exit /b 0
)
:::::::::::::::::::::::::::::
:: Size String ::
:::::::::::::::::::::::::::::
:getSizeString (
set String=%~1
set /a "CountString=0"
call :getSizeStringLoop
exit /b 0
)
:getSizeStringLoop (
set "String=%String:~1%"
set /a "CountString+=1"
if defined String (
goto :getSizeStringLoop
)
exit /b 0
)
::::::::::::::::::::::::::::::
:: Masking Password ::
::::::::::::::::::::::::::::::
:getMaskingPassword (
set "network_pass="
for /f %%a in ('"prompt;$H&for %%b in (0) do rem"') do (
set "BS=%%a"
)
set /p "=%~2" < nul
)
:getMaskingKeyLoop (
set "key="
for /f "delims=" %%a in ('xcopy /l /w "%~f0" "%~f0" 2^>nul') do (
if not defined key (
set "key=%%a"
)
)
set "key=%key:~-1%"
if defined key (
if "%key%"=="%BS%" (
if defined network_pass (
set "network_pass=%network_pass:~0,-1%"
set /P "=!BS! !BS!" < nul
)
) else (
set "network_pass=%network_pass%%key%"
set /p "=*" < nul
)
goto :getMaskingKeyLoop
)
echo/
set "%~1=%network_pass%"
goto :eof
)
:::::::::::::::::::::::::::::::
:: Create Hosted Network ::
:::::::::::::::::::::::::::::::
:setNetwork (
call :PainText 09 "Hosted Network Setting"
netsh wlan set hostednetwork mode=allow ssid="%~1" key="%~2" > nul
call :PainText 02 " [Done]"
echo.
exit /b 0
)
:startNetwork (
call :PainText 02 "Network Starting"
netsh wlan start hostednetwork > nul
call :PainText 02 " [Done]"
echo.
exit /b 0
)
:stopNetwork (
call :PainText 0e "Hosted Network Stoping"
netsh wlan stop hostednetwork > nul
call :PainText 02 " [Done]"
echo.
exit /b 0
)
:PainText (
for /f "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
exit /b 0
)
:ModeUse (
echo Mode Use to Create Network correctly
echo Command: [CreateNetwork]
echo Arguments:
echo -- First parameter: [-stop (Network Stop)], [Network User]
echo -- Second Parameter: [Network Key]
echo.
echo Example:
echo -- CreateNetwork "My first network" "My secure key"
echo.
echo Author:
call :PainText 0e "-- Jerson A. Martinez M. (Side Master - Core Stack)"
echo.
exit
)
:Finished (
set /p selection=Waiting answer:
if [%selection%]==[] (
goto :Finished
)
if %selection% EQU 1 (
goto :Init
)
if %selection% EQU 2 (
call :stopNetwork
)
exit
)
endlocal
exit