Created
February 9, 2020 10:24
-
-
Save ahmdrz/7d70b49c93c44c9a280645f83a96c269 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# your ip address | |
ip_address="192.168.15.142" | |
function change_dns() { | |
route add default gw 192.168.14.200 | |
echo "nameserver 80.191.216.2" > /etc/resolv.conf | |
echo "nameserver 8.8.8.8" >> /etc/resolv.conf | |
echo "nameserver 4.2.2.4" >> /etc/resolv.conf | |
} | |
function change_ip() { | |
ip addr del $1/23 dev enp3s0 | |
ip addr add $2/23 dev enp3s0 | |
} | |
function check_internet() { | |
ping -c 1 gstatic.com 1> /dev/null 2>&1 | |
result=$? | |
return $result | |
} | |
old_target=$ip_address | |
echo "~ checking nodes in network ..." | |
targets=$(nmap -sP 192.168.14.0/23 | grep -Po "([0-9]{1,3}[\.]){3}[0-9]{1,3}") | |
echo "~ checking intenet access for each nodes ..." | |
for target in $targets; do | |
if [[ $target == "192.168.14.200" ]]; then | |
continue | |
fi | |
change_ip $old_target $target | |
change_dns | |
sleep 1 | |
check_internet | |
if [[ $? -eq 0 ]]; then | |
echo "$target" | |
fi | |
old_target=$target | |
done | |
echo "~ removing old ip address ..." | |
change_ip $old_target $ip_address | |
change_dns | |
sleep 1 | |
echo "~ smile and have fun !" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment