Has Anybody Heard of Proxy Switcher? That's the Nuts and Bolts of What I'm Trying to Do, But Simpler
by des_a from LinuxQuestions.org on (#6E07Y)
I'm trying to make some simple scripts that know what network I'm on, and configure it accordingly. Nothing as fancy as proxy switcher for windows, but the same concept. I want to be able to detect an unknown network, and do whatever I want when it's detected, and when I'm on my home network, I want to know about it, and configure the network for just that.
I wouldn't care, but some places my home configuration does NOT work. At the local college, which is not my school, but they have a library, is one place. When I connect to their network, I cannot access the Internet.
Now I'm facing two main problems. Problem one, is I can't seem to install a line into my system wide crontab, and I really need to study how it works again, but I think the system wide crontab is "probably?" best. Problem two, is that while it detects that it's not at my home, very well, and is now out and about, the computers default configuration that it's generating, still is NOT working, but that might work at home. If possible, I don't want to bring down the whole samba server, when I'm out.
The current intent with this program, just to get it out there, so I don't give the wrong impression, is just to use it as part of my standard network configuration. However, I may eventually add what it becomes to another type of linux distribution, for a long time later, maybe my own version, but not in the form it comes in today. The priority is to get it working for my home. It's not like languages I'm working on, which I'm trying to get more public though. Unless someone wants to invent it, or tell me about something invented already, I don't want to do for priority put this in software for everybody.
I'm working on my language on my home, but most of my priorities first, is to get my home working for me. That seems to include increase of linux and decrease of windows. This is part of getting my home working. I'll attatch what I've got so far:
basic_internet_check.sh
Code:#! /bin/sh
echo Performing basic Internet checks...
echo
echo Network DNS server...
ping -c 4 192.168.1.10 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Clientrouter...
ping -c 4 192.168.2.1 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo OpenDNS server 1...
ping -c 4 208.67.222.222 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo OpenDNS server 2...
ping -c 4 208.67.220.220 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Google DNS 1...
ping -c 4 8.8.8.8 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Google DNS 2...
ping -c 4 8.8.4.4 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Spectrum...
ping -c 4 www.spectrum.com > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Google...
ping -c 4 www.google.com > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo
exit 0basic_network_check.sh
Code:#! /bin/sh
echo Performing basic network checks...
echo
echo Loopback...
ping -c 4 127.0.0.1 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Clientrouter...
ping -c 4 192.168.2.1 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Clientrouter mainrouter...
ping -c 4 192.168.1.2 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Mainrouter...
ping -c 4 192.168.1.1 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Mainrouter PFSense...
ping -c 4 192.168.0.2 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo PFSense...
ping -c 4 192.168.0.1 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo
exit 0set_dns.sh
Code:#! /bin/sh
echo Testing network...
sh /usr/bin/basic_network_check.sh > /dev/null
if [ $? -eq 1 ]; then
echo Fail...
sudo systemctl enable systemd-resolved
sudo systemctl start systemd-resolved
exit 1
fi
echo Success...
echo Fix resolv.conf...
sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved
sudo rm -f /etc/resolv.conf
sudo cp -f /usr/bin/stub-resolv.conf /etc/resolv.conf
sh /usr/bin/basic_internet_check.sh
if [ $? -eq 1 ]; then
echo No Internet...
else
echo Internet...
fi
exit 0install_set_dns.sh
Code:#! /bin/bash
echo Installing Set DNS...
(crontab -l ; echo "* * * * * root sh set_dns.sh") | crontab -
#sudo echo "* * * * * root sh set_dns.sh" >> /etc/crontab
echoinstall.sh
Code:#! /bin/sh
echo "Installing..."
sudo cp -f scripts/* /usr/bin
sudo chmod +x /usr/bin/basic_network_check.sh
sudo chmod +x /usr/bin/basic_internet_check.sh
sudo chmod +x /usr/bin/set_dns.sh
sudo chmod +x /usr/bin/install_set_dns.sh
echo
I wouldn't care, but some places my home configuration does NOT work. At the local college, which is not my school, but they have a library, is one place. When I connect to their network, I cannot access the Internet.
Now I'm facing two main problems. Problem one, is I can't seem to install a line into my system wide crontab, and I really need to study how it works again, but I think the system wide crontab is "probably?" best. Problem two, is that while it detects that it's not at my home, very well, and is now out and about, the computers default configuration that it's generating, still is NOT working, but that might work at home. If possible, I don't want to bring down the whole samba server, when I'm out.
The current intent with this program, just to get it out there, so I don't give the wrong impression, is just to use it as part of my standard network configuration. However, I may eventually add what it becomes to another type of linux distribution, for a long time later, maybe my own version, but not in the form it comes in today. The priority is to get it working for my home. It's not like languages I'm working on, which I'm trying to get more public though. Unless someone wants to invent it, or tell me about something invented already, I don't want to do for priority put this in software for everybody.
I'm working on my language on my home, but most of my priorities first, is to get my home working for me. That seems to include increase of linux and decrease of windows. This is part of getting my home working. I'll attatch what I've got so far:
basic_internet_check.sh
Code:#! /bin/sh
echo Performing basic Internet checks...
echo
echo Network DNS server...
ping -c 4 192.168.1.10 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Clientrouter...
ping -c 4 192.168.2.1 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo OpenDNS server 1...
ping -c 4 208.67.222.222 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo OpenDNS server 2...
ping -c 4 208.67.220.220 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Google DNS 1...
ping -c 4 8.8.8.8 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Google DNS 2...
ping -c 4 8.8.4.4 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Spectrum...
ping -c 4 www.spectrum.com > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Google...
ping -c 4 www.google.com > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo
exit 0basic_network_check.sh
Code:#! /bin/sh
echo Performing basic network checks...
echo
echo Loopback...
ping -c 4 127.0.0.1 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Clientrouter...
ping -c 4 192.168.2.1 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Clientrouter mainrouter...
ping -c 4 192.168.1.2 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Mainrouter...
ping -c 4 192.168.1.1 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo Mainrouter PFSense...
ping -c 4 192.168.0.2 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo PFSense...
ping -c 4 192.168.0.1 > /dev/null
if [ $? -eq 1 -o $? -eq 2 ]; then
exit 1
fi
echo
exit 0set_dns.sh
Code:#! /bin/sh
echo Testing network...
sh /usr/bin/basic_network_check.sh > /dev/null
if [ $? -eq 1 ]; then
echo Fail...
sudo systemctl enable systemd-resolved
sudo systemctl start systemd-resolved
exit 1
fi
echo Success...
echo Fix resolv.conf...
sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved
sudo rm -f /etc/resolv.conf
sudo cp -f /usr/bin/stub-resolv.conf /etc/resolv.conf
sh /usr/bin/basic_internet_check.sh
if [ $? -eq 1 ]; then
echo No Internet...
else
echo Internet...
fi
exit 0install_set_dns.sh
Code:#! /bin/bash
echo Installing Set DNS...
(crontab -l ; echo "* * * * * root sh set_dns.sh") | crontab -
#sudo echo "* * * * * root sh set_dns.sh" >> /etc/crontab
echoinstall.sh
Code:#! /bin/sh
echo "Installing..."
sudo cp -f scripts/* /usr/bin
sudo chmod +x /usr/bin/basic_network_check.sh
sudo chmod +x /usr/bin/basic_internet_check.sh
sudo chmod +x /usr/bin/set_dns.sh
sudo chmod +x /usr/bin/install_set_dns.sh
echo