-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpistarscanner.bat
194 lines (167 loc) · 6 KB
/
pistarscanner.bat
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
@echo off
setlocal EnableDelayedExpansion
chcp 65001 >nul
for /f "tokens=3" %%i in ('reg query HKEY_CURRENT_USER\Console ^| findstr /i "VirtualTerminalLevel"') do (
if "%%i" neq "1" (
reg add HKEY_CURRENT_USER\Console /v VirtualTerminalLevel /t REG_DWORD /d 1 /f >nul
)
)
set "RED=[31m"
set "GREEN=[32m"
set "YELLOW=[33m"
set "CYAN=[36m"
set "RESET=[0m"
title Pi-Star Network Scanner
echo %CYAN%======================================================
echo Created by W8RJB ©2024 TechRay Apps LLC
echo %YELLOW%Disclaimer: Use this script at your own risk. We are not
echo responsible for any loss or damage caused by running
echo this script.
echo ======================================================%RESET%
:ask_to_proceed
echo %CYAN%Would you like to proceed? [Y/N]%RESET%
set /p user_choice=Enter your choice:
if /i "!user_choice!"=="Y" (
goto :choose_connection_type
) else if /i "!user_choice!"=="N" (
echo %RED%Exiting the script. Goodbye!%RESET%
goto :end
) else (
echo %RED%Invalid choice. Please enter Y to proceed or N to exit.%RESET%
goto :ask_to_proceed
)
:choose_connection_type
echo %CYAN%======================================================
echo Is your Pi-Star connected via Ethernet or Wi-Fi?
echo 1. Ethernet
echo 2. Wi-Fi
echo =======================================================
set /p connection_type=Enter your choice (1 or 2):
if "!connection_type!"=="1" (
goto :ethernet_scan
) else if "!connection_type!"=="2" (
goto :wifi_scan
) else (
echo %RED%Invalid choice. Please enter 1 for Ethernet or 2 for Wi-Fi.%RESET%
goto :choose_connection_type
)
:ethernet_scan
echo %CYAN%======================================================
echo Scanning for active Ethernet connections...
echo ======================================================%RESET%
setlocal enabledelayedexpansion
set /A count=0
for /f "tokens=1-5 delims=:" %%a in ('ipconfig ^| findstr /R /C:"^Ethernet adapter" /C:"^ *IPv4 Address"') do (
if "%%a %%b %%c %%d %%e"=="Ethernet adapter" (
set /A count+=1
set adapter%%count%%=%%f
set "description[%%count%%]=%%f"
)
if "%%a"=="IPv4" (
set "ip[%%count%%]=%%c"
)
)
if !count!==0 (
echo %RED%No active Ethernet connections found.%RESET%
goto :end
)
echo %YELLOW%Available Ethernet connections:%RESET%
for /L %%i in (1,1,!count!) do (
echo %%i. !description[%%i]! (!ip[%%i]!)
)
echo Press the number corresponding to the Ethernet network your Pi-Star is connected to or press [I] for "I don't know":
set /p ethernet_choice=Enter your choice:
if /i "!ethernet_choice!"=="I" (
echo %YELLOW%Scanning all Ethernet connections for Pi-Star...%RESET%
goto :scan_ethernet_networks
)
if "!ip[%ethernet_choice%]!"=="" (
echo %RED%Invalid choice. Please try again.%RESET%
goto :ethernet_scan
)
set selectedEthernetIP=!ip[%ethernet_choice%]!
set baseEthernetIP=!selectedEthernetIP:~0,-1!.
echo %YELLOW%Scanning the selected Ethernet network: !selectedEthernetIP!...%RESET%
goto :scan_ethernet_specific
:scan_ethernet_specific
for /L %%i in (1,1,254) do (
set ip=!baseEthernetIP!%%i
echo Checking IP: !ip!
ping -n 1 -w 30 !ip! | find "TTL=" >nul
if !errorlevel! equ 0 (
curl -s --connect-timeout 0.3 -I http://!ip!/ | findstr "200 OK" >nul 2>&1
if !errorlevel! equ 0 (
curl -s --connect-timeout 0.3 http://!ip! | findstr /i "pi-star" >nul 2>&1
if !errorlevel! equ 0 (
echo %GREEN%Pi-Star found at IP address: !ip!%RESET%
set found=true
set piStarIP=!ip!
goto :open_browser
)
)
)
)
goto :not_found
:scan_ethernet_networks
for /L %%i in (1,1,!count!) do (
set baseIP=!ip[%%i]:~0,-1!.
for /L %%j in (1,1,254) do (
set ip=!baseIP!%%j
echo Checking IP: !ip!
ping -n 1 -w 30 !ip! | find "TTL=" >nul
if !errorlevel! equ 0 (
curl -s --connect-timeout 0.3 -I http://!ip!/ | findstr "200 OK" >nul 2>&1
if !errorlevel! equ 0 (
curl -s --connect-timeout 0.3 http://!ip! | findstr /i "pi-star" >nul 2>&1
if !errorlevel! equ 0 (
echo %GREEN%Pi-Star found at IP address: !ip!%RESET%
set found=true
set piStarIP=!ip!
goto :open_browser
)
)
)
)
)
goto :not_found
:wifi_scan
echo %CYAN%======================================================
echo Scanning Wi-Fi network range for Pi-Star...
echo ======================================================%RESET%
for /f "tokens=3" %%i in ('netsh interface ip show addresses "Wi-Fi" ^| findstr "IP Address"') do set localIP=%%i
if not defined localIP (
echo %RED%Could not find an active Wi-Fi connection.%RESET%
goto :end
)
for /f "tokens=1,2,3 delims=." %%a in ("%localIP%") do set baseIP=%%a.%%b.%%c.
echo %YELLOW%Scanning Wi-Fi network range %baseIP%.x for Pi-Star...%RESET%
set found=false
for /L %%i in (1,1,254) do (
set ip=%baseIP%%%i
echo Checking IP: !ip!
ping -n 1 -w 30 !ip! | find "TTL=" >nul
if !errorlevel! equ 0 (
curl -s --connect-timeout 0.3 -I http://!ip!/ | findstr "200 OK" >nul 2>&1
if !errorlevel! equ 0 (
curl -s --connect-timeout 0.3 http://!ip! | findstr /i "pi-star" >nul 2>&1
if !errorlevel! equ 0 (
echo %GREEN%Pi-Star found at IP address: !ip!%RESET%
set found=true
set piStarIP=!ip!
goto :open_browser
)
)
)
)
:not_found
echo %RED%No Pi-Star device was found.%RESET%
goto :end
:open_browser
if "!found!"=="true" (
echo %CYAN%Opening the Pi-Star Dashboard in your default web browser...%RESET%
start http://!piStarIP!
)
:end
echo %CYAN%Press any key to exit...%RESET%
pause >nul
exit