I made a script to change ip to 192.168.x.2, then curl 192.168.x.1, x is 0 to 10 with iteration. Just change the for to any you want if you want more. It will curl on 192.168.x.1 addresses to find a web recovery. From 192.168.0.1, to 192.168.10.1 it will curl those addresses. If there is a web recovery you will see any other message then failed.
#!/bin/bash
# Get the name of your Ethernet interface (assuming it's enp3s0, change if needed)
interface="enp3s0"
# Iterate over IP addresses and gateways
for i in {0..10}; do
new_ip="192.168.$i.2"
new_gateway="192.168.$i.1"
netmask="255.255.255.0"
# Change the IP address, netmask, and gateway
sudo ifconfig $interface $new_ip netmask $netmask
sudo route add default gw $new_gateway $interface
# Create a temporary file
temp_file=$(mktemp)
# Test the connection to the gateway and save the output to the temporary file
echo -e "\nTesting connection to the gateway..."
curl_output=$(curl $new_gateway 2>&1)
echo "$curl_output" > $temp_file
# Check if the temporary file contains the specific error message
if grep -q "Failed to connect" $temp_file; then
echo "Warning: Failed to connect to the gateway ($new_gateway). Please check your network settings."
else
echo "Connection to the gateway ($new_gateway) successful. Received response:"
cat $temp_file
fi
# Remove the temporary file
rm -f $temp_file
# Sleep for a moment before the next iteration
sleep 1
done
Another script like this, but instead we curl to 192.168.1.0 to 192.168.1.255, for stupid TP-LINK routers that have web servers at like 192.168.1.66:
#!/bin/bash
# Set the fixed IP address
new_ip="192.168.1.2"
new_netmask="255.255.255.0"
new_gateway="192.168.1.1"
# Get the name of your Ethernet interface (assuming it's enp3s0, change if needed)
interface="enp3s0"
# Display current network settings
echo "Current network settings for $interface:"
sudo ifconfig $interface
# Change the IP address, netmask, and gateway
sudo ifconfig $interface $new_ip netmask $new_netmask
sudo route add default gw $new_gateway $interface
# Display new network settings
echo -e "\nNew network settings for $interface:"
sudo ifconfig $interface
# Loop through each IP address in the range and curl to it
for ((i=0; i<=255; i++)); do
target_ip="192.168.1.$i"
# Create a temporary file
temp_file=$(mktemp)
# Test the connection to the target IP and save the output to the temporary file
echo -e "\nTesting connection to $target_ip..."
curl_output=$(curl $target_ip 2>&1)
echo "$curl_output" > $temp_file
# Check if the temporary file contains the specific error message
if grep -q "Failed to connect" $temp_file; then
echo "Warning: Failed to connect to $target_ip. Please check your network settings."
else
echo "Connection to $target_ip successful. Received response:"
cat $temp_file
fi
# Remove the temporary file
rm -f $temp_file
done