Skip to content

Commit 69b0639

Browse files
authored
Update common_functions.sh
1 parent 2317040 commit 69b0639

File tree

1 file changed

+3
-35
lines changed

1 file changed

+3
-35
lines changed

common_functions.sh

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,15 @@ is_valid_ip() {
2323
fi
2424
}
2525

26-
# Function to get the local IP address based on the detected platform
26+
# Function to get the local IP address (now prompts user for manual input)
2727
get_local_ip() {
28-
platform=$(detect_platform)
29-
30-
case "$platform" in
31-
"linux")
32-
# For Linux (Debian/Ubuntu/CentOS/Arch)
33-
local_ip=$(ip route get 1 | awk '{print $NF; exit}')
34-
if [ -z "$local_ip" ]; then
35-
local_ip=$(hostname -I | awk '{print $1}')
36-
fi
37-
;;
38-
"wsl")
39-
# For WSL (Windows Subsystem for Linux)
40-
local_ip=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
41-
;;
42-
"windows")
43-
# For native Windows
44-
local_ip=$(powershell.exe -Command "(Get-NetIPAddress -AddressFamily IPv4).IPAddress" | sed 's/\r$//')
45-
;;
46-
*)
47-
echo "Error: Unsupported platform. Attempting manual IP entry."
48-
manual_ip_prompt
49-
return
50-
;;
51-
esac
52-
53-
# If the retrieved IP is invalid or restricted, prompt for manual input
54-
if ! is_valid_ip "$local_ip"; then
55-
echo "Warning: Detected IP ($local_ip) is invalid or in a restricted range (172.x.x.x, 127.x.x.x, 0.0.0.0, localhost)."
56-
manual_ip_prompt
57-
fi
58-
59-
# Save the valid IP to a file for sharing
60-
echo "$local_ip" > local_ip.txt
28+
manual_ip_prompt
6129
}
6230

6331
# Function to prompt the user for manual IP input and retry until valid
6432
manual_ip_prompt() {
6533
while true; do
66-
read -p "Please enter a valid external IP manually: " manual_ip
34+
read -p "Please enter a valid machine IP manually(usullay start with 192.): " manual_ip
6735
if is_valid_ip "$manual_ip"; then
6836
local_ip="$manual_ip"
6937
echo "$local_ip" > local_ip.txt

0 commit comments

Comments
 (0)